Simple vb program using arrays

  • 13 years ago

    Hey guys!!! what's up?! please help... can u like give me some sample ... simple examples of program using vb 6 application that has arrays? I'm going to use this as an example for my first year students... this is my first time in teaching actually so i really need your help... tnx!!!

  • 13 years ago

    Hi mommyshe,

    Here I've got 2 example that you can use as your sample program that has an arrays.

    In the first example you need to open a form and put one command button. Then apply this code.

    Option Explicit
    Dim MyMonth, ThisY2k
    Dim i As Integer

    Private Sub Command1_Click()
    For i = 0 To 3
        Print Tab(30); ThisY2k(i)
    Next
    End Sub

    Private Sub Form_Load()
    ThisY2k = Array("Cat", "Mouse", "Dog", "Cat")
    'Return value assume lower bound = 1
    MyMonth = ThisY2k(0)
    'You can change value in the bracket from 1-4
    End Sub

    For the second example, just open a form and put two command button in it. Apply this code.

    'Initializing an array
    Option Explicit

    Private Sub Command1_Click()
    Dim s(9) As Integer
    Dim x As Integer

    Call Cls

    'Initialize array to even elements
    For x = LBound(s) To UBound(s)
        s(x) = 2 + 2 * x
    Next x

    Print "Index" & Space$(3) & "Value"

    For x = LBound(s) To UBound(s)
        Print Space$(2) & x & Space$(7) & s(x)
    Next x

    End Sub

    Private Sub Command2_Click()
    End
    End Sub

    You can try this first and if this simple enough than you can use it.

     

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC. As potential programmers, they are mentally mutilated beyond hope of regeneration.” - E. W. Dijkstra