Declaring an array RRS feed

  • Question

  • I want to use an array to store answers to some questions taken on a test.  I do not plan on storing them into a database, I just want to store the answers while the student is taking the test.

    I have tried declaring an array as a test as Dim newscores(50) as String  and this code is behind button1 on a form; I also assign values into the array at that time.  I also have a listbox on the same form and with a second button2 I want to display an item out of the array into the next row in the list box.  That works if I declare the array behind the button1.  If I create a second button and want it to display another array item into the list box, it says the arrary does not exist.

    Where can I put the array declaration so that it can be seen from anywhere in the project?

    Sunday, November 16, 2008 7:57 PM


  • Outside of the methods but inside the class:

    Code Snippet


    Public Class Form1

    Private myArray(50) As String

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub

    End Class



    Sunday, November 16, 2008 8:08 PM