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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array Function in VB

Status
Not open for further replies.

sjh

Programmer
Oct 29, 2001
263
US
Hi, I am trying the following code, but it doesn't seem to work. Please advise what I am doing wrong. Thank you!

Dim a
Dim strTemp as string

strTemp = "one, two, three"
a = Array(strTemp)
ID = a(1)

 
Dim strTemp AS string

strTemp = Array("one", "two", "three")
ID = strTemp(1)

Remmeber that unless you declare Option Base 1, your array will be '0' index, so in the above example, strTemp(1) = "two"

Hope this helps.


Leigh Moore
LJM Analysis Ltd
 
Hi,

I need to pass strTemp variable as an argument to the Array function.

I tried the following, but they don't work either.

strTemp = "a, b, c"
strSelectedPerf = """a""" & "," & """b""" & "," & """c"""
 
...I need to pass strTemp variable as an argument to the Array function....

Perhaps if you indicated what it is that you are really trying to do someone here can assist you. There are other ways to handle array-like data beyond simple arrays, e.g. ranges, collections and variants. Where are the data coming from? What processing is required? How are you handling the results?

You didn't indicate what application this is for: Excel? Word? Access?

Also, this is the VBA forum. If your question is really for VB, you should post in that forum.
 
I will try to be more specific. This code is for Excel VBA. I have a for loop in my code that iterates and appends values to the strTemp variable. (strTemp = strTemp + someValue + ",") In the end, strTemp will contain a value like this. strTemp = "a,b,c"

I want to convert this strTemp into an array, and that was why I attempted to use the Array() function. But it seems like it won't take a variable as an arugment.

Thanks
 
So... why not define arrTemp as a variant and load it directly instead of first building a string (or do it at the same time if you need both):
Code:
   i = i + 1
   arrTemp(i) = someValue
You can pass the variant to a function and reference it as if it were an array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top