Solved

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

Posted on 2004-09-16
7
497 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 50 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

726 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