Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Question on Arrays

Status
Not open for further replies.

ralphtrent

Programmer
Jun 2, 2003
958
US
Hi
I want to pass an array into a class. I need to make the array available to the entire class, but I am stuck on how to do that.

I have tried to dim array() as string before my subs but then how do I set the value of the array. I thought about create a New sub for the class that has a parameter which is data, then I would like to populate teh array with that data. I have tried to just pass in a string of data and then create the array useing the split command, but that does not seem to work.

So to sum it up, I need to create a array bu passed ni values that will be available to the entire class.

Thanks,
RT
 
Hi, try this

Code:
dim MyArray() as String
dim a as string ="Hello my friend"

MyArray=Split(a," ")  'The " " is the delimiter

For i as int16 =0 to UBound(a)   'index starts from zero
  msgbox MyArray(i)               'in our case UBound(a)returns 2
Next

Ok ???
 
Assuming you have an array in class A, and you want to use the array in class B. Also assuming that the array is of type String.

Code:
class A
 public sub DoThing()
   dim MyArray() as string
   'populate MyArray
   
   dim objB as new B(MyArray)
   objB.DoOtherThing
 end sub
end class

Code:
class b
 private m_MyArray() as string

 public sub New(InputArray() as string)
  m_MyArray = InputArray
 end sub

 public sub DoOtherThing()
   'Do thing that needs array, 
   'use m_MyArray
 end sub
end class

-Rick

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

[monkey] I believe in killer coding ninja monkeys.[monkey]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top