Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 527
  • Last Modified:

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

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
erhunse
Asked:
erhunse
  • 3
  • 2
1 Solution
 
snavebelacCommented:
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
 
erhunseAuthor Commented:
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
 
snavebelacCommented:
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
 
erhunseAuthor Commented:
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
 
snavebelacCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now