User Input
This tutorial will look at handling the input that the user gives us. We will look at several methods of retrieving user input.First create a new project like in the last tutorial. Bring up the toolbox and properties if the are not already there. Insert a command button by clicking on the icon in the toolbox and then clicking and dragging on the form.

Change the button caption to 'Say Hello'.

Insert a textbox and place it just above the button. You insert it the same way a a Command Button. To find out which items in the toolbox are which just hover your mouse aver them and wait for the tooltip to appear. Insert a label to the left of textbox but quite close as this will tell the user what to put in the textbox. Change the text property of the textbox to nothing so it appears blank. Change the caption property of the label to 'Name:'.

This is the graphical part of our project done, so now we need to move onto the code.
The Code
First we need to detect when the command button is clicked. VB does this for us so all we need to do is double click the button which brings up the code window. You will notice the cursor is inside these two lines of code:Private Sub Command1_Click() End Sub
Now we will display a message saying hello.
call MsgBox("Hello " & Text1.Text, vbOKOnly, "A Message")
Now run your program and click the button. You can keep or discard this project as we will be using some of the same parts in the next tutorial (Variables). I usually discard projects as it is very quite and easy to build an interface and it is a bother saving and finding projects. I would recommend creating a new folder for each project and keeping all of the files in the one folder.
© Jonathan Waller 2005; QuantumState Visual Basic




