?
Solved

ASP/VB Script: how do i assign dynamic variables into an array

Posted on 2004-09-16
7
Medium Priority
?
509 Views
Last Modified: 2008-03-10
hello
I have a dynamically created form. Based on available values from my database.

Now when i user checks what he wants on the check box, it passes the variables to the other page, where i would want to use an array to catch all the values available.

I am using the script below to try and catch all variables, which i want to restrict to 6

Here is the script i am using, but keep getting the error "type mismatch"

a=0
for each item in request.form
arrayMe(a) = request.form(item)
a = a+1
next

for a = 0 to Ubound(arrayMe)
response.write arrayMe(a)

next


any advice ? Or coudl anyone assist me with a different mechanism of getting this done ?

thanks
0
Comment
Question by:erhunse
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 6

Expert Comment

by:snavebelac
ID: 12079615
Hi

Would this be better.  Get rid of the array altogether...

For Each item In Request.Form
 Response.Write(Request.Form(item))
Next

This will achieve exactly the same result.  If you want to limit the output to the first 6...

a = 0
For Each item In Request.Form
  If a > 6 Then Exit For
  Response.Write(Request.Form(item)
  a = a + 1
Next

Let me know if I have misunderstood the question

C
0
 

Author Comment

by:erhunse
ID: 12079646
thanks a lot snavebelac
My problem is in 3 fold

THREE PROBLEMS:
1. Picking variables from a dynamic generated form
2. Assigning variables to an array
3. Create a repeated region for the array

I would want to be able to assign variables to the array, based on form variables from a form.

Now, the form that would pass the variables generates dynamic form elements.
How could i:

1. Get all the values from the dynamic form
2. Assign them to an array
3. Create a repeated region for the array(s). Using

for each
response.write(array(0))
next

Any Advice ?
thanks
0
 
LVL 6

Expert Comment

by:snavebelac
ID: 12079746
I understand you need to get variable from a dynamically created form.  How is the form created and what values are assigned to the name and value fields of the form inputs?

I am not sure what you mean by a repeated region of the array.  Perhaps if you can explain exactly what you are doing I may be able to help.  If you could also post all your relevent code, that would help.

C

0
 

Author Comment

by:erhunse
ID: 12079812
thanks again,
snavebelac  But the code i am trying to generate is not a static laid down code.

PROBLEM
I am working on a script, such that, whenever products or a classified section from my site is choosen, it would generate a search based on the choosen category ie

if www.domain.com/?product=electronics

all electronics category woudl be generated ie using the while/wend function. This would generate all the values corresponding to this field and check boxes to match.

SOLUTION
When the user picks a certain product in this category, the script
For Each item In Request.Form
 Response.Write(Request.Form(item))
Next
 
would pick the variables.

WHAT I WANT:
Simply to be able to assign the values of the form to an array. All the others, i could get done, once i assign this. As stated in my first post above. Or simply:

WHAT IS WRONG WITH MY FIRST POST, assigning values from a form into an array ?

Thanks
0
 
LVL 6

Accepted Solution

by:
snavebelac earned 200 total points
ID: 12079896
My apologies... I misunderstood

Try declaring the size of your array first...

Dim arrayMe(Request.Form.Count)

a=0
for each item in request.form
arrayMe(a) = request.form(item)
a = a+1
next

for a = 0 to Ubound(arrayMe)
response.write arrayMe(a)
a = a + 1 (I think you will need this line)
next

The Forms collection's first ndex is 1, not 0 (zero)

Let me know if this helps.

C
0

Featured Post

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question