Adding Code For The Program

The crucial step in building a Visual Basic application is to write code using the BASIC language. This is the most time consuming task in any Visual Basic application.
Code is placed in code window. At the top of code window two boxes will apllear ,the object (or control) list and the procedure list.Select an object and the corresponding event procedure. A blank procedure will appear in window where you write BASIC code.
After designing interface the next step is to associate the code with the controls.
Suppose you have to write code for commandButton.Then Ensure that you have selected the commandButton.
Double click on the commandButton.This will bring up the command window as shown in the figure below:
The ‘Code Window‘ is where you write code for your VISUAL BASIC application.It is used to write code for various events supported by the controls. In code Window you have to select the control and event for which the code is to be written.
Suppose you have clicked command button .Then code window displays the following lines:
Private Sub Command1_Click( ) End Sub
Any code written between these lines will be executed when the control by the name of ‘Command1’ is clicked upon.
VISUAL BASIC makes the writing code easier with the features that can automatically fill in properties and syntax.
For example, When you enter name of a control followed by a period in your code,the ‘Auto List Members’ feature presents a drop-down list of properties available for that control.
Add the following Code between above lines as shown in figure:
Text1.Text = “Hello Visual Basic
VISUAL BASIC automatically verifies the correct syntax after you enter a line of code.It also capitalizes the first letter of command words and often adds extra spaces for readability.
The above written line of code simply changes the Text property of the control named Text1 to ‘Hello VISUAL BASIC’.
Syntax: object. Property
At runtime above code simply displays a textbox containing Text “Hello Visual Basic“, just like below:
Scroll to Top