Writing and Running the Code
You will learn how to interact with users and run the program
Interacting with the User
The intermediary between you, the programmer, and the users out there is the user form. You have learned how to put the textbox and the command button in the previous chapter. This time, you are going to use it. Make a user form with basic textboxes, labels, and a command button similar to the one below.
Writing the Code
Simply double click any element on your user form to begin writing code. To start off, double click "Button1" and see a code screen come up. When you type in the code for your program on this screen, make sure that you are referring to the right elements and variables all the time. You do not want to end up jumbling your data. If you are referring to data in Textbox1 then make sure that you don't have the data of Textbox3 in mind. Once you get all things organized, your code may look like the one below.
Visual Basic is very user friendly. As you can see, simply double clicking a feature on your user form will automatically insert code. In the code above, take note that the "Val()" code is used to differentiate text from numerical value. Try removing the Val() code and see what happens to the result. You will learn little tidbits of coding as you go along this tutorial so pay attention and absorb all this knowledge.
Running the Program
Once you have the code in place, press F5 or the "play" button on the task bar. You will enter "debug" mode. Test your program and see if it works. If you want to exit debug mode, simply press the "X" button on the upper right corner of the user form or the "stop" button on the task bar.