previous page main page next page

Notice that the Caption property for each of the command buttons has an ampersand - a '&' character - in it and this has the effect of underlining the letter that follows it. When you run the program, users now have a choice of using the mouse to click on a button or using a key combination. Let's see how it works...
 

  • enter the code for the Exit button in the usual way
  • run the program
  • hold the ALT key and press the 'x' key
     

So holding the ALT key and pressing the underlined letter has the same effect as clicking the button with a mouse. Clearly you must make sure that each button has a different letter that's underlined - you can't have two buttons with the same key combination. We're going to use this technique in all future projects.

OK, so we want the user to type in their name and their age. It looks like we have two variables, then. The user's name is a string, or text, variable and we'll call it UserName. The person's age is an integer and we'll call it Age...

...and now for some history:

If you've ever used a typewriter - well, we did say history - you'll know that when you want to start a new line, you have to do a line feed and a carriage return. The first of these moves the paper up a line and the second moves you to the start of the line. Curiously, this has survived into the computer world, albeit in an electronic way, and we are going to need the electronic equivalent when we print out our results.

The upshot is that we really need to declare another variable called LFCR (Line Feed, Carriage Return) which we can use to do the job for us. You'll see how it works a little later but for now we need to declare all three variables in the General Declarations section of the project.
 

  • declare the variables like this:
     


 

Here's the code for the cmdDetails Click event:

Private Sub cmdDetails_Click()

UserName = InputBox("Please enter your name:")
Age = InputBox("please enter your age:")

End Sub
 

  • type in the code
  • run the program
     

You see now what's meant by an input box. This is one of the joys of Visual Basic - you can use all these fancy tools with minimal effort...which leaves you free to concentrate on what your program should be doing.

Continued...
 

previous page main page next page ©  ePublish Scotland  1999