473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Reading Form values into a Scripting.Dictionary

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
2 3401
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
"=?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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Wilson | last post by:
Hello friends, I have this dynamic array(shown below) that I need to match to values (1 - 10) that I am returning from the database via DSN connection object. The values I need to match are on...
8
by: Rodd Snook | last post by:
I have an application which makes extensive use of the Scripting.Dictionary object. I'm not doing anything silly like putting them outside the page scope -- just creating quite a few of them and...
9
by: What-a-Tool | last post by:
Dim MyMsg Set MyMsg = server.createObject("Scripting.Dictionary") MyMsg.Add "KeyVal1", "My Message1" MyMsg.Add "KeyVal2", "My Message2" MyMsg.Add "KeyVal3", "My Message3" for i = 1 To...
5
by: Richard Cornford | last post by:
I am interested in hearing opinions on the semantic meaning of FORM (elements) in HTML. I have to start of apologising because this question arose in a context that is not applicable to the...
17
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
14
by: ericellsworth | last post by:
Hi, I'm trying to use a class to pass variables back and forth from a form opened in dialog mode. I have created a class which invokes a form in its show method, like so: Public Sub Show() '...
6
by: Oenone | last post by:
Could someone suggest a good native .Net collection object that provides similar functionality to the COM Scripting.Dictionary object? Specifically I need to be able to add items with an...
7
by: Dan | last post by:
(Using Classic ASP & MS Access) I have a page that has 120 fields on it (mostly checkboxes). I cannot split this into smaller pages. So what i want to do is write a class that handles this. in...
3
by: jaffar.kazi | last post by:
Hi All, I have a VB COM component that has an object of type Scripting.Dictionary. Each element of this again has Scripting.Dictionary type members. I need to access this in C#, and am not able...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.