Visual Basic Programming

Activity 1: Visual Basic

“Visual Basic (VB) is a programming environment from Microsoft in which a programmer uses a graphical user interface (GUI) to choose and modify preselected sections of code written in the BASICprogramming language.”

create project

First, create a new project to make a form. Add 4 buttons and three textbox. Set the 4 buttons as “Add“, “subtract“, “multiply“, and “divide“. On the 3rd textbox you will need to disable it as well. To do this, click the textbox and set the enable to solution explorer as “false” After doing all of these, it will look like in the image below.

activity 1activity 1

Codes: 

“In the first Public sub class, the code “Dim” or also known as Dimension is a variable that is a declaration or you are telling VB that you are setting up a variable.

After the Dim word, VB looks for the name of your variable. Though you can call your variables you like, there are a few words that Vb won’t allow So you set them as e.g num1, num2, num3, etc. Type “As integer” afterwards, for this tells VB that the variable is going to be a number or an integer.

Double click a button in order to write the code. The code window will appear and click anywhere to type in the code. For the First Public class, you will type the following code in the picture below:

codes

The Button 1 will be the “add” button. This allows you now to add numbers.

Double click another button and type the code on the picture below to the code window.codes

The button 2 will be the “subtract” button.  This allows you now to subtract numbers.

The same as the last step, click another button to open the code window and type the code in the picture on the picture below:

codes 2

The button 3 will be the “multiply” button.  This allows you now to multiply numbers.

On the last button, repeat the last step and then type the code on the picture below:

codes 2

The button 4 will be the “divide” button.  This allows you now to divide numbers.

After completing all of these steps, click debug in order to identify if it works or not. You can also calculate numbers after doing this.

Meaning of terms used in codes:

Private – That no other part of the program can see this code except for our button.

Sub – It tells VB that some code follows, and that it needs to be executed.

Button1 – Name of the button. Even if you erased the word “Button 1” when you changed the text property, it still called Button 1 because its Name property is more important one.

The equal (=) sign is not actually an equal sign. It means “Assign a value of“. This is where you put something in your variable. This is a way to tell VB to assign a value of 3 to variable called number 1.

Leave a comment