Arcade Prehacks

Results 1 to 4 of 4
  1. #1
    variable's Avatar
    Join Date
    Dec 2010
    Location
    Neverland
    Posts
    91

    All about variables - VB 6 & .NET

    This is my tutorial for variables.
    As always, this is for Visual Basic 6.0 and .NET


    What is a variable?
    -----------------------
    Variable is a medium in which you can store values for read and
    write procedures.


    How to declare a variable:
    --------------------------------
    The following is the syntax for declaring variables in vb6 and
    .NET:

    Visual Basic 6:
    Code:
    Dim (variable name) [As] {variable type}
    Legend:
    Terms in () = Required
    Terms in [] = Optional
    Terms in {} = Optional but must be provided if the previous
    one was provided (i.e As)

    Now, to declare a variable called x you would just type Dim x.

    In this way, the variable would be a VARIANT. That is, it can
    take the form of ANY variable.

    Visual Basic .NET:
    Code:
    Dim (variable name) [As] {variable type} [=] {Data}
    Legend:
    Terms in () = Required
    Terms in [] = Optional
    Terms in {} = Optional but must be provided if the previous
    one was provided (i.e As, = )

    The declaration of variables in .NET is next to same as VB 6.
    The difference is that you can set a default value for the
    variable as you declared it (like constants but changeable).

    Example:
    Dim FileCount As Integer = 5



    Before you can understand thsese.. You'll need basic knowledge
    on a few types of variables.

    The ones you are going to use in your program more than any other
    are:

    1. Integer
    2. Double
    3. String
    4. Long
    5. Boolean

    Integer:
    An integer is a variable which can hold any small amount of number.
    For example: 10. Or 3000.
    An Integer can hold up to about 33000 to -33000 (not sure).
    That is not the count of the numbers.
    It is the highest value it can hold.
    That is, if you assign an integer a value of 40000 then that would
    create and error. An overload error. In such large number cases, you
    need to use Double.


    Double:
    A double acts same as an integer. But double's data holding capacity
    is much higher than that of integer. It is recommended to use double
    in calculators. As the values are frequently expressed in decimals and
    are large in size.


    String:
    This is the most used variable in ANY project.
    A string can hold messages or information to show to the user or to
    use for other purposes. To make it clear, a string is like a notepad.
    It can hold various things. You may write numbers or letters in it.
    For example, you declare a variable called Msg. That is: Dim Msg.
    Now, if you change it to: Dim Msg As String, then the variable Msg
    would be able to be used for string purposes.
    That is, Msg = "Hello"
    Now type MsgBox Msg. And see the variable Msg shown.

    Two strings can be concentrated using "&". Example:
    Dim String1 As String, String2 As String
    String1 = "Hello"
    String2 = "World"
    MsgBox String1 & " " & String2

    So, that's it for strings. NEVER try to do calculations using strings.
    You will get type mismatch or similar error if you do.


    Long:
    Same as double and integer but can hold larger amount of numbers than
    double.
    This is mainly used for API call purposes..


    Boolean:
    Booleans are a special kind of variable which can store data in True
    or False way. That is a variable called NameExists which is declared
    as a boolean can hold either True or False in it. Which can be Read
    or written later.
    That is:

    Code:
    Dim NameExists As Boolean
    If txtName.Text = "" Then
      NameExists = False
    Else:
      NameExists = True
    End If
    I hope you got that.


    That's it for variables.
    There are tons of more variables out there for you to use..
    Experiment with it..


    -BladeX

  2. #2

    Join Date
    Jun 2011
    Posts
    17

    Re: All about variables - VB 6 & .NET

    ~Nice tutorial. It's good for people who are thinking about experimenting with vb, although it reminds me of one i've read before... Anyway good job!

  3. #3
    variable's Avatar
    Join Date
    Dec 2010
    Location
    Neverland
    Posts
    91

    Re: All about variables - VB 6 & .NET

    Thanks man!
    Btw, you have just bumped this topic...

  4. #4
    Senior Member
    Join Date
    Nov 2009
    Location
    California
    Posts
    2,212

    Re: All about variables - VB 6 & .NET

    ugh dont bump old topics (user warned)


    sorry bladex but locked

    (mods feel free to unlock)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •