CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Feb 2008
    Posts
    2

    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

  2. #2
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    Re: Array across classes

    You might get more help in the .NET forum - this is VB6 but your code is .NET
    Be nice to Harley riders...

  3. #3
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Array across classes

    You need to instantiate the class
    Code:
    Dim K as New DBsystem
    '  K.Fullname
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  4. #4
    Join Date
    Feb 2008
    Posts
    2

    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

  5. #5
    Join Date
    Sep 2000
    Location
    Indianapolis
    Posts
    6,758

    Re: Array across classes

    moved.
    -----------------------------------------------
    Brad! Jones,
    Yowza Publishing
    LotsOfSoftware, LLC

    -----------------------------------------------

  6. #6
    Join Date
    Mar 2007
    Location
    Argentina
    Posts
    579

    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

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured