Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
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:
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now