Can this be done through array?

M

Maurice

Hi guys,

Just wondering if someone can help me with the following situation.

I'm working on this template that needs to be filled with data. The data and
macro are kicked of via a vbscript which has among others the line:

..run "Main", "Array("test", "option", "answer","name","")"

This refers to Main which is the name of the routine and the second set
provides the data. This would be an Array of data.

The question I have is how to provide the template with the correct argument
for the array so i can treat it as an array.

So fa I came up with this:

Private sub Main (arrTest as Variant)
dim x as integer

for x=0 to ubound(arrTest)
debug.print arrTest(x)
next
end sub

i do use the IsArray option to check if it's an array which tells me it's not.
This doesn't work because it's giving me a datatype error. When changing it
i can get it to read the total string but then i want to be able to point to
the certain elements of the string for instance debug the third element like:

debug.print arrTest(2,x) '-is this correct?

Furthermore i'm thinking that if some records for a database are handled
like this how does one go about finding the next record in the array? Let's
say in the example above if the second record would start at the "answer"
field. My guess would be that it has to be unique to be determined what the
next record would be right?

So one final question... what does an array look like when exported to a
textfile. The above sample is provided to me to work with. It's created via
Java. So the normal output of an array would look like:

"option1", "option2", "option3" etc..
or
"Option1, Option2, Option3" etc...

Hope someone can shed some light on this one for me i'm stumbled.
 
D

Doug Robbins - Word MVP

Use

Dim myarray as Variant

myarray = Split(("test,option,answer,name",",")

Then you will have an array myarray containing the items "test", "option",
"answer" and "name".

Check out the Split function for more information on its use.

--
Hope this helps

Doug Robbins - Word MVP
Please reply only to the newsgroups unless you wish to avail yourself of my
services on a paid, professional basis.
 
G

Gordon Bentley-Mix

It appears that Doug - who is usually really good about this sort of stuff
;-P - inadvertently added an extra left bracket to his sample code. It
should read:

myarray = Split("test,option,answer,name", ",")

In addition, if at all possible I'd try to find a way to use a less common
character than a comma for the delimiter for the Split function. I usually
use a pipe (|) because, while there may be times when I want an array value
to contain a comma, it's less likely that I'll ever want one to contain a
pipe. So for me the code would look like:

myarray = Split("test|option|answer|name", "|")
 
M

Maurice

Doug,

Thanks for the pointer. As a matter of fact i was playing around with the
split function to see if that could help me. Funny you pointed me in that
direction.

i'll give it a shot
 
M

Maurice

Hi Gordon,

Thanks for the tip. The data i'm receiving is being prepared by another
party which chooses the "," sign. So my guess is I just have to work hard to
get it right :)

But for future cases the pipe seems like a good alternative.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top