How to Use Multiple Calls Within Visual Basic
A "call" within the Visual Basic language is what a Visual Basic software application does to follow the next step of the written code. Calls can be used to make Visual Basic calculate numbers, compare items or condense the same set of steps in sequence that might happen more than once. The best way to see how a call works is to write the code in a Visual Basic developer environment. You can use multiple calls within a Visual Basic program to create rich and user-friendly software applications.
Things You'll Need
- Pen
- Paper
- Visual Basic Express installed on a PC
- Visual Studio.NET installed on a PC (optional)
Instructions
-
-
1
Write down with pen and paper the different functions or routines you would need your application to perform. For example, if you were building a calculator, you would need functions such as "Calculate," "Exit" or "Clear." If you are building a database meant to search for information, you might need a "Sort," "Delete" or "Update" function.
-
2
Open your developer environment. You can use the free Visual Basic Express edition for a developer environment by downloading it from Microsoft.com. Visual Studio.NET is the full version that allows programmers to make complex computer programs. Open the project you are currently working on.
-
-
3
Click on an item you already have in place on the form to take you to the coding screen. Double-clicking on an item creates a new module with a "Private Sub" and an "End Sub" displaying on the code screen where you can type the code you need to make each item, function, routine or sub routine work.
The code you need for each module will be different for each function or routine you are working with. You'll also notice that whatever item you clicked on to get to the coding screen will be automatically added to the end of "Private Sub." For example, the "Exit" button will say "Private Sub Exit" in the coding screen.
-
4
Call the routines, functions and sub functions by typing "call Private Sub (name of module) ()" without the parentheses around the name and quotation marks substituting the name of the coded module inside the parentheses.
For example, if you wanted the application to exit when the user hits the "Exit" button and a "Finish" button, you would type "close ()" between the "Private Sub Exit" and "End Sub" sections for the "Exit" module and then "call Private Sub Exit ()" without the quotation marks under the "Finish" module between "Private Sub Finish" and "End Sub."
If you want the "Calculate" function to happen every time a person presses an operator button for addition, subtraction and so on, type "call Private Sub Calculate ()" without the quotation marks in the module of each operator button.
-
5
Press "File" at the top of the menu choices and then choose "Save All Files" when you are finished. Close the developer environment.
-
1
Tips & Warnings
If you find yourself repeating the same set of code to perform a function or routine multiple times during the coding phase, then it's a good indication you can create a sub module out of that one piece of code. Once it's created, you can "call" it anywhere else you need that function to take place, saving you keystrokes and keeping your code a bit easier to read.
Routines, sub routines and functions are useless unless the routines and functions do something to process information or display results. Therefore, you must put items on a blank form, name the items and your variables prior to adding the Visual Basic code for the module to work.
References
- Photo Credit notebook image by Alexander Ivanov from Fotolia.com