Link to home
Start Free TrialLog in
Avatar of codequest
codequest

asked on

How to clear and reuse an Array

How might I clear and reuse an array?  Something like this (which doesn't work).

dim ar() as string = {"XYZ","ABC","123"}
Do_A(ar)
ar.clear                                   << doesn't work
ar() = {"PQR","HJK","435"}        << doesn't work
Do_B(ar)

I'm using these arrays as low-syntax, easy to maintain temporary value holders, for use in building an in-memory data structure.
I'd like to avoid having to declare a new array every time I want to use it as a temporary value holder.

Any suggestions would be appreciated.

Thanks!
SOLUTION
Avatar of hatem72
hatem72

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of hatem72
hatem72



for dealing with data try this :

    Public Structure employees

        Dim EmpID As Integer
        Dim EmpName As String
        Dim EmpAdd As String

    End Structure

    Dim MyArray(5) As employees
...

        MyArray(1).EmpAdd = EmpAddVar
        MyArray(1).EmpID = EmpIDVar
        MyArray(1).EmpName = EmpNameVar

if isnt clear i am here
Avatar of codequest

ASKER

Thanks for the input.   I'll check out the array reset's a little later and let you know if I can get them to work.
Thanks for the info and example on structure.  That's very helpful...I hadn't figure those out yet.
Question:  where do I declare structures?  At the top of classes?  Inside methods?
Thanks!
Also, if I use a structure in one class, how do I make it available in another class...do I have to redefine it there?
Thanks!


u can Declare structure like any variables anywhere (Not in Procedure level )

http://msdn2.microsoft.com/en-us/library/k69kzbs1(VS.80).aspx

my Example :

Imports System.Windows

Public Class MyClassName

    Public Structure employees

        Dim EmpID As Integer
        Dim EmpName As String
        Dim EmpAdd As String

    End Structure
    Dim MyArray(5) As employees

    Public Sub PopData()
       
        MyArray(1).EmpAdd = EmpAddVar
        MyArray(1).EmpID = EmpIDVar
        MyArray(1).EmpName = EmpNameVar

    End Sub

...
...
...

End Class

'  Another Class to write Data ( Just Example )

Public Class MyClassName

   Public Sub GetData()
       
        EmpAddVar=MyArray(1).EmpAdd  
        EmpIDVar=MyArray(1).EmpID
        EmpNameVar=MyArray(1).EmpName

    End Sub


End Class
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
PockyMaster:  good stuff, very handy, thanks!

hatem72:  please collect extra points at a question I'll enter with
Q_21788716.html#16289923 in the title...just make any enty and I'll accept it as the answer

codequest