Today you will create your Third project in the Visual Studio environment! This will be a desktop application - for a Personal Computer (PC). We will use Visual Basics (VB.NET) as a Programming Language.

Today, you will create the "Calculator". You will learn how to work with variables and use simple mathematical operations.

We will create the same project using different programming languages (VB.NET, C#, C++, Python, Java Script) and on different platforms (Desktop app, Web App, Mobile App, Arduino project). This is what makes the MATRIX an unique programming learning methodology.

MATRIX team

Visual Basic

PROJECT 3.1.1
Calculator

 

For our projects, we will use the Microsoft Visual Studio application. It allows you to create projects in different programming languages and on different platforms. We guess you already have Visual Studio on your PC. If not, download and install Visual Studio on your Personal Computer from the next link:
Download Visual Studio >>>

Our Online Simulator will help you to make the project "Calculator".

Now a little theory for our project:

1. Variables

In VB.NET, variables serve the purpose of holding data values, and they need to be defined with both a name and a type. Values can be assigned to variables at the time of declaration or afterwards. The scope of a variable defines the locations in a program where it can be accessed.

VB.NET supports various data types, including:

Integer: Whole numbers.

String: Text.

Boolean: True or false values.

Decimal: Numbers with a fractional part, with higher precision than Single or Double.

Single, Double: Floating-point numbers (numbers with a fractional part).

Date: Date and time values.

Array: A collection of elements of the same data type. 

 

Dim X As Integer

Dim Y as Decimal = 3.7

Dim Minus As Boolean = True

 

In the first line, we declare a variable "X" with the type Integer without assigning a value.

In the second line, variable "Y" with the type Decimal and assigned value 3.7

In the third line, we declared a variable "Minus" with a Boolean type and assigned the value True.

 

2. Message Box

Message Box Displays a message in a dialog box. We are using a simple Message Box in our project. Here is an example:

MsgBox(" some text here ")

More information about different types of Message Boxes can be found here: https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/msgbox-function

 

 

 

3. If - ElseIf - Else

You know how to use the If operator. Else If is for adding one more condition. Else means that code written after Else will run if none of the above conditions is right.

Example:

If a>b then
MsgBox("More")
ElseIf a<b
MsgBox("Less")
Else
MsgBox("Equal")
End if

 

4. Val

We are using Val in front of TextBox.text, to tell the program text in the text boxes are numbers, so it is possible to compare them or perform other mathematical operations.

Example:

If Val(TextBox2.Text) > Val(TextBox1.Text) Then
MsgBox("guessed number is less")

 

Now it is time to start the simulation. Repeat the stages the simulator shows you in your Visual Studio.

 

Conclusion:

You have created the game "Guess Number" in the Visual Studio environment with the VB.Net programming language. At first, we worked on the program interface (visual side), after we wrote the programming code.

Now you know how to use If-ElseIf-Else construction, making Message Boxes and Random Numbers generators.