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!
LVL 2
codequestAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hatem72Commented:


ar = Nothing ' Will set the refrence of the array to nothing

OR

ReDim ar(0)
0
hatem72Commented:


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
0
codequestAuthor Commented:
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!
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

codequestAuthor Commented:
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!
0
hatem72Commented:


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
0
PockyMasterCommented:
ReDim is oldschool VB stuff.

They've invented Array now.

'init some array
 Dim ar() As String = {"123", "12312", "123"}

'e.g. clear all the items
Array.Clear(ar, 0, ar.Length)
'e.g. resize it
 Array.Resize(ar, 2)
'e.g. copy another array into your array
   Array.Copy(New String() {"12312", "123123"}, ar, 2)

there's more where that came from...

good luck
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
codequestAuthor Commented:
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
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.