• home
  • forum
  • my
  • kt
  • download
  • The Basics of Visual Basic

    Author: 2007-09-05 18:06:42 From:

    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!

    discuss this topic to forum

    relation tutorial

    No relevant information

    Category

      .NET (8)
      Buttons (3)
      Database Related (7)
      Date and Time (1)
      Development (3)
      Error Handling (2)
      File Manipulation (5)
      Introduction to Visual Basic (9)
      Miscellaneous (2)
      Multimedia (9)
      Networking (9)
      Security (1)
      VB Script (6)

    New

    Hot