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!

Array assistance 2

Status
Not open for further replies.
Oct 11, 2006
300
US
Hi,

I request for form variables. I would like to grab all the values and dump into an array. How can I do that?

I am trying to modify this part of the code to my case. I request from another form. I do not request from a URL.

Code:
'/// Collect the Values wanted into the dictionary object
for i = lbound(aParams) to ubound(aParams)
    aKeyValue = split(aParams(i),"=")
    skeyWord = request.QueryString.Key(i+1)
    sIDX = skeyWord
    sParam = aKeyValue(ubound(aKeyValue))
    dList.add sIDX, aKeyValue(ubound(aKeyValue))
next

I thought that the values I get from the Request.form can be dumped into a single dimensional array. But from what I see in the code, it looks like it is looping through a multidimensional array.

Thanks.

Thanks.
 
try this:

Code:
<%
dim myarray
For x = 1 to Request.Form.Count
myarray(x-1) = """&Request.Form.Item(x)&"""
Next 
'to check the values
for i=0 to ubound(myarray)
response.write myaaray(i) & <br>"
next
%>

-DNG
 
When I try this:

Code:
<%
dim myarray
For x = 1 to Request.Form.Count
[b]myarray(x-1) = """& Request.Form.Item(x) &"""[/b]
'myarray = """&Request.Form.Item(x)&"""
Next
'to check the values
for i=0 to ubound(myarray)
response.write myaaray(i) & "<br>"
next
Response.End
%>

I get an error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch
 
I also tried this:

Code:
<%
dim myarray
For x = 1 to Request.Form.Count
	'myarray(x-1) = """& Request.Form.Item(x) &"""
	myarray = Request.Form.Item(x)
	Response.Write Request.Form.Item(x) & "&"
	'myarray = """&Request.Form.Item(x)&"""
Next
'to check the values
for i=lbound(myarray) to ubound(myarray)
	response.write myaaray(i) & "<br>"
next
Response.End
%>

I now get the error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'lbound'

When I try this:

[code]
<%
dim myarray
For x = 1 to Request.Form.Count
	'myarray(x-1) = """& Request.Form.Item(x) &"""
	myarray = Request.Form.Item(x)
	Response.Write Request.Form.Item(x) & "&"
	'myarray = """&Request.Form.Item(x)&"""
Next
'to check the values
for i=0 to ubound(myarray,2)
	response.write myaaray(i) & "<br>"
next
Response.End
%>

I get the error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch: 'ubound'

Any ideas how to dump the request.form items into the array and print it.

Thanks.
 
DNG,

Did my suggestion help? thread183-1314659

-George

Strong and bitter words indicate a weak cause. - Fortune cookie wisdom
 
When I tried your suggestion:

Code:
<%
dim myarray
For x = 1 to Request.Form.Count
	[b]myarray(x-1) = """& Request.Form.Item(x) &"""[/b]
	'myarray = Request.Form.Item(x)
	Response.Write Request.Form.Item(x) & "&"
	'myarray = """&Request.Form.Item(x)&"""
Next
'to check the values
for i=0 to ubound(myarray,2)
	response.write myaaray(i) & "<br>"
next
Response.End
%>
I get an error:

Error Type:
Microsoft VBScript runtime (0x800A000D)
Type mismatch

Error is at the above line which is bold.

Thanks.
 
I've never referenced a Request.Form value using the .Item property. Back to the original question, do you really need to dump every value coming in from Request.Form into an array? The Request.Form object is essentially already an array, sort of like a dictionary object because you can reference the fields by name instead of position. But if you want to put all of the values in Request.Form into an array, here's what I see as the easiest way:
Code:
Dim formArr()
i=0
For Each elem in Request.Form
   formArr(i) = Request.Form(elem)
   i = i+1
Next
That will populate the formArr array with all of the values in the Request.Form object. They won't be indexed by name anymore, however, just the integer that marks their position in the array. From the example you can see how to use a simple For loop to access all elements in a Request.Form object, so you could always change the processing code to meet your needs.

PS I think all of the type mismatches from the previous posts may be caused by the "dim myarray" line - which should read "dim myarray()" in order to declare it as an array variable.

Hope this helps!
 
ok do this:

<%
dim mystring, myarray
mystring = ""
For x = 1 to Request.Form.Count
mystring = mystring & "," & Request.Form.Item(x)
Next

myarray = split(mystring,",")

'to check the values
for i=0 to ubound(myarray)
response.write myaaray(i) & <br>"
next
%>

George,
I did not check your post yet...i will check and reply...thanks

-DNG
 
Ecwecee,

When I tried your example,

Code:
<%
Dim formArr()
i=0
For Each elem in Request.Form
   [b]formArr(i) = Request.Form(elem)[/b]
   i = i+1
Next

Response.End
%>

I get the error at the line bold above:

Error Type:
Microsoft VBScript runtime (0x800A0009)
Subscript out of range
 
Strange. How are you processing these items that you need them in an array? Whatever you want to do with them could likely be done inside the For Each xxx in Request.Form loop without need of putting them first in an array. Otherwise I guess you'll have to use the method already suggested by DNG above - concatenating all elements into a string with a delimiter and using the split function to create an array. The danger in that method, however, is that it could break apart a value if the delimiter was entered into the form field.
 
Basically I just want the entire form elements from the previous page.

and implement them in this sample code:

In this code, the form elements from a URL querystring. In mine, it is not coming that way. I get it through Request.Form

So even if I were not to dump the Request.Form into an array as you mentioned, and use it as it is already an array, then how I implement my Request.Form array in the following example?

Code:
'dim sStr
'sStr = request.QueryString
dim aParams : aParams = split(sStr, "&")
dim aKeyValue, i, sIDX
dim sKeyword, sParam
dim dList : set dList = Server.CreateObject("Scripting.Dictionary")
Dim Keys, Items, param, crystalparam

'Collect the Values wanted into the dictionary object
for i = lbound(aParams) to ubound(aParams)
    aKeyValue = split(aParams(i),"=")
    skeyWord = request.QueryString.Key(i+1)
    sIDX = skeyWord
    sParam = aKeyValue(ubound(aKeyValue))
    dList.add sIDX, aKeyValue(ubound(aKeyValue))
next
 
So you're trying to take everything in Request.Form and construct a querystring out of it?
Code:
Dim strQuerystr, j
strQuerystr = ""
j = 0
For Each elem in Request.Form
   If j>0 Then strQuerystr = strQuerystr & "&" End If
   strQuerystr = strQuerystr & elem & "=" & Request.Form(elem)
   j = j+1
Next
After that loop is complete the variable strQuerystr will have every value in Request.Form concatenated into a querystring of with form field name = form field value.
 
Hi,

In the line bold below, how can I replace it with the strquerystr

Code:
'/// Collect the Values wanted into the dictionary object
for i = lbound(aParams) to ubound(aParams)
    aKeyValue = split(aParams(i),"=")
    [b]skeyWord = request.QueryString.Key(i+1)[/b]
    sIDX = skeyWord
    sParam = aKeyValue(ubound(aKeyValue))
    dList.add sIDX, aKeyValue(ubound(aKeyValue))
next
 
Well strQuerystr is the whole querystring, and it looks like in your code there you're going item-by-item. I think that skeyWord is the actual field name, which I'm pretty sure is the same as the value in aKeyValue(0), also known as aKeyValue(LBound(aKeyValue)). Does that sound right?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top