Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Reading Form values into a Scripting.Dictionary

Reply
Thread Tools

Reading Form values into a Scripting.Dictionary

 
 
Tim Chmielewski
Guest
Posts: n/a
 
      06-21-2004
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
 
Reply With Quote
 
 
 
 
Scott McNair
Guest
Posts: n/a
 
      06-22-2004
Tim Chmielewski <(E-Mail Removed)> wrote in
news:Xns950F6DB987B6Fchumadcsinetau@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.
 
Reply With Quote
 
 
 
 
Tim Chmielewski
Guest
Posts: n/a
 
      06-23-2004
"=?Utf-8?B?U3RlcGhlbk1jQw==?=" <(E-Mail Removed)>
wrote in news:(E-Mail Removed):


> - 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: Reading Multiple Values from List using JSP and Form Post Method Lew Java 0 02-09-2008 08:57 PM
reading form values and passing them to querystring Paul Czubilinski Javascript 3 12-01-2006 06:22 PM
Reading integer values from a txt file and save them into an array zigbeedeep@gmail.com Java 1 09-29-2006 02:38 AM
Reading fields and their values from a signed PDF form dr-ffm Perl Misc 1 04-02-2006 01:17 PM
simple js dynamically reading form values - js fails - why? Randell D. Javascript 1 11-25-2003 06:57 AM



Advertisments