469,325 Members | 1,526 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,325 developers. It's quick & easy.

Dynamic Variables with unknown constant

Hi All,

This one is a bit complex, so I'll try to be as logical explaining the issue as humanily possible.

ASP/VBScript/MySQL

Issue: Creating dynamic variables while there is an unknown constant

Example: Somebody uses a drop down menu to select the type of fruit. Let's say they select apples. Now directly underneathe, a table of checkboxes is returned with all the possible results (chkbx1 = granny's, chkbx2 = smith, chkbx3 = mcintosh, and so on). The possible chkbx's are contained within a MySQL table - retrieving/displaying them is no issue. But now, each of those checkboxes must have a separate variable attached when they are called through a DO WHILE...LOOP.

ie: chkbx1, chkbx2, chkbx3, etc.

However, if someone decided to choose a different fruit, and it produced 10 results with checkboxes, it would need to dimension 10 variables. This can vary for a variety of different selections - and while we know how many are in the database, we won't know which selection from the dropdown is going to be made - and not wanting to write unique code for each of the possible scenarios - I figure there must be an easier way.

I thought of running a self-adding interger in the loop to identify them - but I don't know how to actually dimension them before hand like this...and then know this amount so I can later check the boolean results of each.

If this makes sense and you can assist, I'd be greatful.

Thank you,
Jeremy
Aug 3 '07 #1
2 1312
jhardman
3,406 Expert 2GB
Jeremy,

from what I gather, I've done something similar. The last time I tried this I dimmed a gigantic array (like 200 items) and looped through them to put all of the inputs in their place. This was time consuming and probably not the best use of the cpu.

It might be better to give the inputs all the same name, then the post data should return this:
Expand|Select|Wrap|Line Numbers
  1. request("appleCheckBoxes") = "on,,,on,on"
and you can send these all to an array with the split command like this:
Expand|Select|Wrap|Line Numbers
  1. appleChecks = split(request("appleCheckBoxes"), ",")
  2. for each x in appleChecks
  3.    response.write x & ": " appleChecks(x) & "<br>" & vbNewLine
  4. next
This should return the following:
Expand|Select|Wrap|Line Numbers
  1. 0: on
  2. 1:
  3. 2:
  4. 3: on
  5. 4: on
does this help?

Jared
Aug 3 '07 #2
Hi Jared,

Thanks - yes this does help...ingenious, and I feel mental for not thinking of it myself. One of those many times that you stare at a problem for so long - you lose all comprehension of it.

Thanks again.
Cheers,
Jeremy


Jeremy,

from what I gather, I've done something similar. The last time I tried this I dimmed a gigantic array (like 200 items) and looped through them to put all of the inputs in their place. This was time consuming and probably not the best use of the cpu.

It might be better to give the inputs all the same name, then the post data should return this:
Expand|Select|Wrap|Line Numbers
  1. request("appleCheckBoxes") = "on,,,on,on"
and you can send these all to an array with the split command like this:
Expand|Select|Wrap|Line Numbers
  1. appleChecks = split(request("appleCheckBoxes"), ",")
  2. for each x in appleChecks
  3.    response.write x & ": " appleChecks(x) & "<br>" & vbNewLine
  4. next
This should return the following:
Expand|Select|Wrap|Line Numbers
  1. 0: on
  2. 1:
  3. 2:
  4. 3: on
  5. 4: on
does this help?

Jared
Aug 7 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

10 posts views Thread by Dave Karmens | last post: by
2 posts views Thread by Tommy Lang | last post: by
2 posts views Thread by systemutvecklare | last post: by
1 post views Thread by Nathan Bloomfield | last post: by
2 posts views Thread by deejayquai | last post: by
18 posts views Thread by squaretriangle | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by mdpf | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.