HOW TO! Some ideas that may help…..

 

Produce a random number:

 

Visual Basic includes a function that generates random numbers.  Try adding a textbox to a form and adding this to a button;

Text1.Text = RND

The random function (RND) creates numbers greater 0 and less than 1. 

To get random number in a range from 0 to a larger maximum number multiply RND by the maximum you require + 1

e.g. Text1.Text = RND * 6 + 1  

To stop the decimal part showing, use the Visual Basic INT function that returns the nearest integer to a decimal number.

So to get random numbers from 0 to 6 use 

Text1.Text = INT ( RND * 6 + 1 )  

 

For more information try the Visual Basic help system.

Make Images move:

 

Create a new form and add an Image control.  Set the Picture property to an image file of your choice.  Set stretch = true to make image fit the control.

The Top and Left properties are the position of the top left corner of the image control by changing these the image should move!

 

Try adding a button and this code.

 

For x = 1 To 100

Image1.Left = Image1.Left + 25

Next x

 

For y = 1 To 100

    Image1.Top = Image1.Top + 25

Next y

 

To make sure that the Image remains on screen make sure that the value of left is never more than the (Form.Width – Image.Width)

 

Do While Image1.Left < (Form1.Width - Image1.Width)

Image1.Left = Image1.Left + 1

          DoEvents

Loop

 

Similar code applies to moving down the form.

 

Making images disappear is done by changing the value of the visible property!

 

Other Graphics

 

Visual Basic does not support graphics very well but you can try these:

 

Line control: simply draws a line, X1Y1 values are one end and X2 Y2 are the other.

 

Play with the DrawMode this effects how the line interacts with the background colours when the program runs.

 

Shape control: draws a range of shapes, has Shape, and Fill values that you can experiment with.

 

Visual Basic also offers a line drawing function which you give parameters (values) to and it draws the required line.

 

Add this to the Click event of a form. 

 

Form1.ForeColor = vbBlack

 

Line (CurrentX, CurrentY)-(CurrentX + Rnd * 1000, CurrentY + Rnd * 1000)

 

This is another case of reading the help system.

 

 

Making a noise!

 

Visual Basic is not very good at sounds; however you can add a multimedia control to your project which can play sound files for you.

 

Start a new project, open the Project menu and select Components, scroll down the controls listed and select the Microsoft Multimedia control.

 

The Multimedia control accepts a number of command words, set the filename property for the control to any ‘.wav’ file.

 

Add to the Form_load()

MMControl1.Command = "Open"

 

Use this line to make the sound play

MMControl1.Command = "Play"

 

If you don’t want the user to see the control on the form set its visible property to false.

 

Once more the Visual Basic help system has a lot of extra information for you.

 

Hosted by www.Geocities.ws

1