previous page main page next page
  • run the program
     

You should check that there are three ways of moving the 'thumb' of the scroll bar. One is by clicking and/or holding the black arrows at either end of the bar. Another is by clicking and dragging the thumb itself. Thirdly, you can click in the bar to either side of the thumb to cause the thumb to move in larger 'jumps' - that's why we set the LargeChange property to 5.
 

  • alter the LargeChange property to, say, 20 and see the effect
     

You'll see that, as well as moving in larger jumps, the width of the thumb has also increased.

The Max property of the bar was set to 100 and the Min property is 0 which gives us a range of values from 0 to 100 as the thumb moves along the bar. These are the values that we're going to use for the number of miles. Before we decide how to convert into kilometers, let's see if we can get the program to display the number of miles in the top text box.

If you've done any programming before, you'll probably have come across the idea of a variable. Our program is going to convert a number of miles into a number of kilometers and because we don't know in advance what these numbers are going to be, we need to use a couple of variables. One variable will be called Miles and the other will be called - you've guessed already - Kilometers and, as the name implies, they are going to vary depending on what the user chooses and what the program calculates.

What sort of numbers are they? Well Miles is going to be a whole number, or integer, between 0 and 100. Kilometers, on the other hand, will be calculated, and is probably going to have a decimal part to it. It's always worth considering these factors before trying to code the program.

The code for the cmdExit button is almost the same as for the last example but we've added just an extra bit of interest:
 

Private Sub cmdExit_Click()

Beep
End

End Sub
 

  • enter this code and run the project
     

You should hear a beep through your computer's speakers when you exit the program. Some would find this irritating after a while but it can have it's uses at times. We just thought we'd mention it anyway...

You'll notice that one of the properties of the scroll bar is called Value. This is the key to the program and it's this that tells us the number of miles that the user has selected. We want our variable called Miles to take on this value and display it in the top text box.
 

Continued...
 

previous page main page next page ©  ePublish Scotland  1999