There is no universal way to do so. I saw the others offered some solutions for some particular cases, but in general you will need to do it "manually".
BTW one idea I am trying to promote from a long time ;) Using collections instead of arrays may be a nice choice sometimes. E.g. instead of Dim arr(20) or Redim ... you can get a dictionary/collection ActiveX and do the same. If the array size is "very" dynamic this will be more convenient for sure. Where to get such collection objects: One that comes with the VBScript runtime libraries is Scripting.Dictionary - see the VBScript docs for more info. Another (mine ;) ) - http://www.newobjects.com/prodct/Category/63 - see VarDictionary. What is better - mine of course (if I am talking about it what else you can expect from me) but forget the jokes - Scripting.Dictionary is built-in that is the only good side. VarDictionary is flexible which makes it more convenient - you can set some general properties and request whatever behavior you need. For example you amy request dict("name") to create element in it or set an existing if an element with this name exists, or you may want to allow unnamed values (just like array) and you will be able to make dict.Add "", something as many times as you need and then you can get the Count, access element as dict(4) or dict(23), remove certain element dict.Remove el_name_or_index and always the Count will show the real number of elements. There are many other advanced features but in general this is the idea: JScript has dynamic arrays and sometimes I prefer it for ASP but if the VBScript is the choice because of some reason I miss them too much and thus I began to use these components in ASP very often (oh yes initially I built them for this http://www.newobjects.com/alp but later I found many other reasons to use them). -----Original Message----- From: Ricki Williams [mailto:[EMAIL PROTECTED]] Sent: Monday, September 02, 2002 10:30 PM To: ActiveServerPages Subject: RE: convert string to array As long as I'm at it...Here's another quick and easy one for you. I have some arrays that are not dynamic (I create them like this: Dim myArray(5)) and then populate them based on form results. Question: Is there a way to tell how many of the indexes in myArray have a value? such as myArray.count? right now I'm looping through and checking to see if the value is null, but I have a feeling there is a better way. Thanks again, Ricki -----Original Message----- From: Michael Elfial [mailto:[EMAIL PROTECTED]] Sent: Monday, September 02, 2002 1:51 PM To: ActiveServerPages Subject: RE: convert string to array Hi Ricki, I have a minute so why not answer in short. I'll explain two ways: Split function: arr = Split(a_string,",") Will split the string into array using the specified delimiter. But I think this is not good way to deal with the multiply choices listboxes. Using the strings collection: If your listbox is like this <SELECT NAME="MyLB">.... Then you will ceive in the Request("MyLB") all the selected values. In fact they are in a collection that can be looped as an array and the comma delimited result is returned only as an alternative. So you can do these things x = Request("MyLB").Count will return the number of the values (the selected values) x = Request("MyLB")(4) will return the 4-th value E.g you can do this For I = 1 To Request("MyLB").Count x = RequesT("MyLB")(I) ' Do something with it Next Or if you prefer enumerations do this For each e in Request("MyLB") ' do something with the e - it contains the value Next I recommend you the second way - the collection because this will save a little memory and in fact acts like an array. Also using split may lead to some mistakes if certain value contains the delimiter in it. This sounds impossible for a listbox but who knows - it is better to use the safest way. Michael -----Original Message----- From: Ricki Williams [mailto:[EMAIL PROTECTED]] Sent: Monday, September 02, 2002 9:37 PM To: ActiveServerPages Subject: convert string to array I know this has to be simple, but I'm not finding the answer and I've never tried it before. I have a list box where they can make multiple selections. A sample return from the box is: African, African - American, Aleutian, American Indian, Asian, Bangladeshi, Bhutanese, Brazilian My question is, how do I loop through this string and change it into an array so I can loop through it for later processing? Or should I even convert it to an array if I can loop through the string just as easily? If that's the case, then I'm still back to - How do I loop through a string? thanks, Ricki --- You are currently subscribed to activeserverpages as: [EMAIL PROTECTED] To unsubscribe send a blank email to %%email.unsub%% --- You are currently subscribed to activeserverpages as: [EMAIL PROTECTED] To unsubscribe send a blank email to %%email.unsub%% --- You are currently subscribed to activeserverpages as: [EMAIL PROTECTED] To unsubscribe send a blank email to %%email.unsub%% --- You are currently subscribed to activeserverpages as: [email protected] To unsubscribe send a blank email to [EMAIL PROTECTED]
