View Full Version : How to ignore real commas when converting to an array?

03-13-2006, 10:08 PM

I am using ASP and a SQL database. Here is something I would think would be a more common issue.

I have an HTML menu list ( "<option>" tag) that pulls it's values from a SQL database. For example lets say these are some of the values that pulled.

Fielding USA
Bigger Buys
Nation Source, Inc.

So if the user where to choose all of these and submit the form, the string would look like this:

mystring = Fielding USA, Bigger Buys, Nation Source, Inc. Sterners

I then convert this to an array by looking at the commas like this


thisArray=Split(mystring ,",") '' Turns the comma seperated string into an array


So as you can see when I convert this to an array the comma after source should be ignored and makes it look like this:

Fielding USA
Bigger Buys
Nation Source

I suppose this is similar to the single quote issue that I see on the sticky, but if I don't have to I don't want to eliminate commas from my data.

Does anyone know a way around this? I was thinking maybe there is a way to tell the option tag to to not use commas to seperate the values? I would rather use something like "|".
Thanks for the help

03-14-2006, 01:22 PM
When receiving the posted form, you should iterate over the selected options to store them in an array instead of just concatenating them to a comma-separated string and later splitting it up into an array

03-14-2006, 01:37 PM
(why cant i edit my own post?)

Dim size = Request.Form("theselectfieldname).Count

For i = 1 To size
'add the ith element of the formcollection to your array
yourarray(i) = request.Form("theselectfieldname")(i)

03-14-2006, 02:23 PM
I would agree with the above method.
Another option is to store the comma as an ASCII value.

03-14-2006, 11:41 PM
Great I like that method. Thanks.

Any idea though how to declare the array because it gives me an error if I don't declare it. If I hard code it with a number like "3" it works. But the number of items in the array will vary. I tried setting it to the size like this:

Dim thisArray(size)

But it causes an error. "Expected integer constant"

Here's the code

Dim size
size = Request.Form("theselectfieldname").Count

Dim thisArray(????)' How to make this dynamic because it wont always be the same

For i = 1 To size
'add the ith element of the formcollection to your array
thisArray(i) = request.Form("theselectfieldname")(i)


Thanks again

03-14-2006, 11:53 PM
In VBScript You must first declare the array with a numerical value. Then you can use the ReDim keyword to declare the array to a different size.

As an example

Dim myArray(3)

Dim x : x = 'assign a numerical value to x
ReDim myArray(x)

03-15-2006, 12:28 AM
I could have sworn I tried the "Redim" and it didn't work, but it works now. Thanks

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum