Global Arrays

dan_score

Member
Joined
Jun 24, 2008
Messages
11
Programming Experience
1-3
Im making a program, and i need to make a global array. I tried declaring it by doing : Dim garrAnswer(9) as globla string

it didn't work, an im sure im doing something wrong because an error popped up, so i was wondering if you cuold tell me how to declare a global array so i can use it when im using a different form in the same program. Thanks.
 
VB.NET:
Public Class GlobalStuff
    Public Shared listAnswer As New List(Of String)
End Class

Public Class MyClass1
    Private Sub SetGlobalArray()
        GlobalStuff.listAnswer.Add("First String")
        GlobalStuff.listAnswer.Add("Second String")
    End Sub
End Class

Public Class MyClass2
    Private Sub UseGlobalArray()
        Dim myVariable As String = GlobalStuff.listAnswer.Item(0)
        MessageBox.Show(myVariable)
    End Sub
End Class
 
alternatively u can create a module and declare
VB.NET:
public garrAnswer(9) as string

in the module
 
alternatively u can create a module and declare
VB.NET:
public garrAnswer(9) as string

in the module

While this is true; I try to avoid compatability/migration carry-overs from VB6 and go with a pure OO alternative.

I'm going to assume this feature will be depricated in some future release.
 
Back
Top