Solved

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

Posted on 2004-09-16
7
496 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
  • 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Edit a page at wix.com 8 69
how to build a intranet site 8 42
hbo knew my windows software 4 62
Code Manager | Snippits 2 37
Envision that you are chipping away at another e-business site with a team of pundit developers and designers. Everything seems, by all accounts, to be going easily.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

827 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