-
Array across classes
Hi Guys,
I am writting a program and have a got a bit stuck. Hope you can help, When the program starts, I call LoadData from within the forms load handle.
This inserts data from a flat file into an array. Its a bit of a bodge job but it does what it needs too :)
What I am trying to do now is call the get method for Fullname to pull the information from "ClientData(i)(0)" with i being the record information..
Code:
Public Class DBSystem
Public i As Integer
Public Sub LoadData()
'DBPath = String containing full path to same dir as where directory + file ext.
'DBAval = If string = nothing then create file
Dim DBPath As String
DBPath = CurDir() + "\database.txt"
If (System.IO.File.Exists(DBPath) = False) Then 'No? then create
My.Computer.FileSystem.WriteAllText(DBPath, "", True) 'Bodge Job to get around File in use/IOException Error
Else
Dim DBRawInput As String 'Load Data into String
DBRawInput = My.Computer.FileSystem.ReadAllText(DBPath)
Dim arraysize As String() = IO.File.ReadAllLines(DBPath)
Dim ClientData(arraysize.Length - 1)() As String 'Two-Dimentional Array, 9 fields required so put as 8.. 0 to 8 = 9
Dim TempArray As New ArrayList(DBRawInput.Split(","c)) 'Split String into one large array
Dim insdatloop As Integer
Dim fullnamenl As String
i = 0
insdatloop = 0
While (i < arraysize.Length) 'Loop for how many lines are within DB
fullnamenl = TempArray(insdatloop) 'Because new Record starts on fresh line, remove line from Array record.
fullnamenl = Replace(fullnamenl, Environment.NewLine, "")
ClientData(i) = New String() {fullnamenl, TempArray(insdatloop + 1), TempArray(insdatloop + 2), TempArray(insdatloop + 3), TempArray(insdatloop + 4), TempArray(insdatloop + 5), TempArray(insdatloop + 6), TempArray(insdatloop + 7), TempArray(insdatloop + 8)}
'Full Name, House Number, Address 1, County, PostCode, Phone, Email, Job Title, Salary
'ClientData(i) = New String() {"", "", "", "", "", "", "", "", ""}
insdatloop = insdatloop + 9
'MsgBox(fullname, MsgBoxStyle.MsgBoxHelp) 'Testing Data/Data Debug
i = i + 1 'Add 1 so loop continues to next level in the multidimentional array
End While
End If
End Sub
Public Property FullName() As String
Get
FullName = ClientData(i)(0)
End Get
Set(ByVal value As String)
End Set
End Property
End Class
Im pulling this information by using
Code:
DBSystem1.i = "0"
txtname.Text = DBSystem1.FullName
Under a button click. Unfortunately I am getting the error that ClientData is not declared in:
Code:
Public Property FullName() As String
Get
FullName = ClientData(i)(0)
End Get
Set(ByVal value As String)
End Set
End Property
How can I get it to work as I need to do this for a number of variables within the class.
Hope you can help,
-Chris
-
Re: Array across classes
You might get more help in the .NET forum - this is VB6 but your code is .NET
-
Re: Array across classes
You need to instantiate the class
Code:
Dim K as New DBsystem
' K.Fullname
-
Re: Array across classes
NP, If a mod would move it, it would be greatly appreciated.
The class is already instantiated in the class for the form.
-Chris
-
Re: Array across classes
-
Re: Array across classes
try:
Code:
Public Class DBSystem
Public i As Integer
Private ClientData()() As String
Public Sub LoadData()
'DBPath = String containing full path to same dir as where directory + file ext.
'DBAval = If string = nothing then create file
Dim DBPath As String
DBPath = CurDir() + "\database.txt"
If (System.IO.File.Exists(DBPath) = False) Then 'No? then create
My.Computer.FileSystem.WriteAllText(DBPath, "", True) 'Bodge Job to get around File in use/IOException Error
Else
Dim DBRawInput As String 'Load Data into String
DBRawInput = My.Computer.FileSystem.ReadAllText(DBPath)
Dim arraysize As String() = IO.File.ReadAllLines(DBPath)
reDim ClientData(arraysize.Length - 1)() As String 'Two-Dimentional Array, 9 fields required so put as 8.. 0 to 8 = 9
Dim TempArray As New ArrayList(DBRawInput.Split(","c)) 'Split String into one large array
Dim insdatloop As Integer
Dim fullnamenl As String
i = 0
insdatloop = 0
While (i < arraysize.Length) 'Loop for how many lines are within DB
fullnamenl = TempArray(insdatloop) 'Because new Record starts on fresh line, remove line from Array record.
fullnamenl = Replace(fullnamenl, Environment.NewLine, "")
ClientData(i) = New String() {fullnamenl, TempArray(insdatloop + 1), TempArray(insdatloop + 2), TempArray(insdatloop + 3), TempArray(insdatloop + 4), TempArray(insdatloop + 5), TempArray(insdatloop + 6), TempArray(insdatloop + 7), TempArray(insdatloop + 8)}
'Full Name, House Number, Address 1, County, PostCode, Phone, Email, Job Title, Salary
'ClientData(i) = New String() {"", "", "", "", "", "", "", "", ""}
insdatloop = insdatloop + 9
'MsgBox(fullname, MsgBoxStyle.MsgBoxHelp) 'Testing Data/Data Debug
i = i + 1 'Add 1 so loop continues to next level in the multidimentional array
End While
End If
End Sub
Public Property FullName() As String
Get
FullName = ClientData(i)(0)
End Get
Set(ByVal value As String)
End Set
End Property
End Class