11th Mar, 2010 - 07:24:57 AM
IF YOU PLAN ON USING THIS WEBSITE PROPERLY, THEN PLEASE ENABLE JAVASCRIPT IN YOUR BROWSER.

YOU WILL NOT FIND ANY MALICIOUS SCRIPTING ON THIS WEBSITE.

YOUR BROWSING EXPERIENCE WILL BE SEVERLY HAMPERED IF YOU DO NOT ENABLE JAVASCRIPT BEFORE CONTINUING.

YOU WILL CONTINUE TO SEE THIS MESSAGE UNTIL YOU ENABLE JAVASCRIPT.
Your are currently not logged in. ( Login / Register )
NAME:   Visual Basic: The Basics
AUTHOR:   punkstar
DATE:   20th Nov, 2005 - 03:17:24 PM
DESCRIPTION:   The usual, loops, variables and conditionals

Need some help with that coding?


Okay, Visual Basic.. what an application. Its so simple to get programs up and running (usually a point, click, drag, type and run =D).

Variables
Variables in VB are declared with the dimension keyword..

Code
Dim variable_name as string


..also you will notice that after the "Dim", then the name there is an "as string" statement. This means that the variable that I declared is of variable type string. This is basically some text. Some other variable types include integer, double, currency, boolean, etc.

Conditionals
The IF statement can help you tell if the a value is equal to something, or not.

Code
Dim Number as integer

Number = 435

If Number > 10 Then
msgbox.show("The number is greater than 10!")
ElseIf Number < 10 Then
msgbox.show("The number is less than 10!")
Else
msgbox.show("The number is 10!")
End If


Looping
If you want something to get done more than one time in visual basic, or any other programming language for that matter.. you will need to loop. There are different types of loops: DO WHILE, DO UNTIL and FOR.

Code
Dim current As Integer
Dim max As Integer

current = 0
max = 100

Do While current <= max
lblResult.Caption = lblResult.Caption & " " & Str(current)
current = current + 1
Loop


Code
Dim current As Integer
Dim max As Integer

current = 0
max = 100

do
lblResult.Caption = lblResult.Caption & " " & Str(current)
current = current + 1
loop until current <= max


You may think that there is not really any difference between the two loops above, but one fundamental difference is that the second loop will execute the code atleast once before the condition is checked.

The final loop is the FOR loop, and it goes a little something like this..

Code
Dim current As Integer
Dim max As Integer

max = 100

For current = 1 to max
lblResult.Caption = lblResult.Caption & " " & Str(current)
next


..and thats it for the basics of Visual Basic! Enjoy!