By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,738 Members | 1,493 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,738 IT Pros & Developers. It's quick & easy.

Reading Form values into a Scripting.Dictionary

P: n/a
I have been trying to read values from a form into an array on a page
without much success and was told to use a Scripting.Dictionary instead.

There are a variable number of fields on the form as it is different
according to which product is ordered (as are the fields that are used to
create the record.)

This is my first attempt:
set OrderInfo = Server.CreateObject("scripting.dictionary")
set OrderInfo("prodid") = Server.CreateObject("scripting.dictionary")
set OrderInfo("userid") = Server.CreateObject("scripting.dictionary")
OrderInfo("prodid") = lngProductID
OrderInfo("userid") = lngUID

For each x in Request.Form
set OrderInfo("prodid")("userid")(x) = Server.CreateObject
("scripting.dictionary")
OrderInfo("prodid")("userid")(x) = Request.Form(x)
Next

For each x in OrderInfo("prodid")("userid")
Response.Write x & " = " & OrderInfo("prodid")("userid")(x) & "<BR>" &
vbcrlf
Next
Thanks.
--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Tim Chmielewski <ch***@dcsi.net.au> wrote in
news:Xn****************************@130.133.1.4:
I have been trying to read values from a form into an array on a page
without much success and was told to use a Scripting.Dictionary
instead.

There are a variable number of fields on the form as it is different
according to which product is ordered (as are the fields that are used
to create the record.)


Wow, that's a lot of scripting.dictionary calls.

Without being totally sure what you're doing, I think you could probably
simplify it down to something like this:

Set OrderInfo = Server.createObject("scripting.dictionary")
For Each Item in Request.Form
OrderInfo(Item) = Request.Form(Item)
Next

That way, if for example you had form items ProductID, Color, and Size,
you would reference them via

Response.Write OrderInfo("ProductID")
Response.Write OrderInfo("Color")
Response.Write OrderInfo("Size")

Hope that helps.
Jul 19 '05 #2

P: n/a
"=?Utf-8?B?U3RlcGhlbk1jQw==?=" <St********@discussions.microsoft.com>
wrote in news:77**********************************@microsof t.com:

- array example:
....Read into dict:
Dim oArray()
ReDim oArray(Request.Form.Count)
For i = 0 To Request.Form.Count
oArray(i) = Request.Form(i)
Next

I ended up using your array example:
' Store Extra Product Fields
Dim ProductFieldsArray()
ReDim ProductFieldsArray(intNumFields)
strSQL = "SELECT FieldName FROM tblProductExtraFields WHERE ProductCode
Like '" & strPC & "'"
Set rstProduct = Server.CreateObject("ADODB.Recordset")
rstProduct.Open strSQL, conConnection
i = 0
Do While Not rstProduct.EOF
ProductFieldsArray(i) = rstProduct("FieldName")
rstProduct.MoveNext
i = i + 1
Loop
rstProduct.Close

' Store form values
Dim oArray()
ReDim oArray(Request.Form.Count)
For i = 0 To Request.Form.Count
oArray(i) = Request.Form(i)
Next

intStopVal = Ubound(oArray)
intStartVal = 4
intSet = Ubound(ProductFieldsArray) - 1
intSetStop = intStartVal + intSet

strSQLStart = "INSERT INTO tblCartExtraInfo(lngUserID, lngProductID"

For n = 0 to Ubound(ProductFieldsArray) - 1
strSQLStart = strSQLStart & ", " & ProductFieldsArray(n)
Next
strSQLStart = strSQLStart & ") VALUES ('" & lngUID & "','" & lngProductID
& "',"

' Checking input values & insert
For i = 0 to 4
strSQLValues = ""
intHasVals = 0
For j = intStartVal to intsetStop
strSQLValues = strSQLValues & "'" & oArray(j) & "',"
if len(oArray(j)) > 0 then
intHasVals = intHasVals + 1
end if
Next
strSQLValues = Mid(strSQLValues,1,len(strSQLValues) - 1) & ")"
strSQLFull = strSQLStart & strSQLValues
intStartVal = intSetStop + 1
intSetStop = intStartVal + intSet
if intHasVals = intSet + 1 then
conConnection.Execute(strSQLFull)
end if
Next
Thanks.
--
GIT Groupie : http://gitgroupie.timchuma.com
The Twits Give Me the Shits : http://twitsgivemetheshits.timchuma.com
My Photos : http://photos.timchuma.com
Hong Kong Movie Reviews: http://hkmovies.timchuma.com
Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.