In Visual Basic 6, we can create a scientific calculator that resembles a typical scientific calculator albeit a simpler version. Other than the number buttons, the operator buttons and some additional buttons such as the memory button and the clear button, we have added all three trigonometric functions and the log functions.
The interface is shown below:
I want you to try writing code for this calculator and I will show you the full code later.
We have learned how to handle decisions making process using If…Then…Else and also Select Case program structures in Visual Basic. Another procedure that involves decisions making is looping. VB allows a procedure to be repeated many times until a condition or a set of conditions is fulfilled. This is generally called looping . Looping is a very useful feature of VB because it makes repetitive works easier. There are two kinds of loops in Visual Basic, the Do…Loop and the For…….Next loop
Learn more about looping in Visual Basic from our updated Visual Basic 6 lesson 9
To control the program flow in Visual Basic 6, we can use various conditional operators. Basically, they resemble mathematical operators. Conditional operators are very powerful tools, they let the Visual Basic 6 program compares data values and then decide what action to take, whether to execute a program or terminate the program and more. Some of the conditional operators are +, -, >, < ,>= and <=.
On top of the conditional operators, there are a few logical operators which offer added power to the Visual Basic programs. They are And, Or, Xor and Not. To effectively control the Visual Basic program flow, we shall use the If…Then…Else statement together with the conditional operators and logical operators.
Read more about conditional and logical operators and the usage of If….Then.. Else in our newly updated and enhanced Visual Basic 6 Lesson 7.
Before we start building a Visual Basic 6 application, we need to understand the basic concepts of properties , events and methods. Every object in VB 6, such as a form , a command button , a text box and more have a set of properties that describe them. Setting the objects’ properties is the first step in building a Visual Basic application, i.e. designing the interface. We will learn more about setting properties in the lesson 3.
The next step in building a Visual Basic application is to write code to response to the events. Events usually comprises actions triggered by the user, such as clicking the mouse buttons, pressing a key on the keyboard, dragging an object and more.
Read more about building Visual Basic applications in our newly updated Visual Basic 6 Lesson 2
VISUAL BASIC is a VISUAL and Event-driven Programming Language. These are the main divergence from the old BASIC. In BASIC, programming is done in a text-only environment and the program is executed sequentially. In Visual Basic 6, programming is done in a graphical environment. In the old BASIC, you have to write program code for each graphical object you wish to display it on screen, including its position and its color. However, In Visual Basic 6 , you just need to drag and drop any graphical object anywhere on the form, and you can change its properties using the properties window.
In addition, Visual Basic 6 is Event-driven because we need to write code in order to perform some tasks in response to certain events. The events usually comprises but not limited to the user’s inputs. Some of the events are load, click, double click, drag and drop, pressing the keys and more. We will learn more about events in later lessons. Therefore, a Visual Basic 6 Program is made up of many subprograms, each has its own program code, and each can be executed independently and at the same time each can be linked together in one way or another.
Read more about Visual Basic 6 in our updated Visual Basic 6 lesson 1