Link LIKE

Thursday, July 23, 2009

Simple Guide to Visual Basic (VB 6.0)

Lets Try a Simple Calculator :



As you start the Microsoft Visual Basic 6.0, You will have see this screen to start your project. The Standard.exe is simple for beginners to use and you will have more control over what you are programming. Since Visual Basic is Object Oriented, in other words every object like buttons and textbox is what controls the function.
Lets say for a calculator below, I Added 4 buttons



The toolbox allows you to draw the buttons and textbox. This is where the design of the interface takes place. You can change the details of the button at the properties tool.



Each of the Object can do an event or action and when you double click the object, you will see two lines of coding, usually start with "Private Sub" and "End Sub". In between those lines you can start coding. Coding is actually easy when you know what you want it to do. Example the "Command1" is actually the button, "Text1" is the textbox, Label1 is the Label. Textbox allows a user to Key in text while Labels cant do so.

Notice the Dim thing in the Code? It is to tell the computer that the information thats taken from the textbox is actually an integer which means numbers. Since you cant "Dim" the Textbox directly, so i used a variable instead.


Then if you want to know whether you type the right code, click play to test the codes. Just like below...



Well Done, thats it. The more you explore, the more you will learn. This is just a simple intro to VB, thats how i learn it in the first place.

The Code :

Private Sub Command1_Click()

Dim Box1, Box2 As Integer
Box1 = Text1.Text
Box2 = Text2.Text
Label1.Caption = Box1 + Box2

End Sub
----------------------------
That is just for the Plus button, Try the other buttons by changing the operator sign (The Operator signs are = + - / * )
And yes, just replace the "+" into the rest...


If it is not simple enough or needs more pictures, please let me know.
The Luminate