473,326 Members | 2,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Changing variable name with loop

2
Hi all,

I've been searching for a while, and have not been able to find a working solution.

I'm trying to change the name of multiple strings within some serverside vbscript, depending on the loop integer.

The code I am trying to loop through is:

Expand|Select|Wrap|Line Numbers
  1.     SQL = "SELECT * FROM tblPackingDetails WHERE ((tblPackingDetails.ShippmentNumber = '"&ShippingNumber&"') AND (tblPackingDetails.CaseNo = '4'))"
  2. Set rs = Server.CreateObject("ADODB.Recordset")
  3.  
  4. rs.open SQL, Conn
  5.  if Not rs.EOF Then
  6.     Case4DimL = rs("CaseDimL")
  7.     Case4DimL = Trim(Case4DimL)
  8.     Case4DimW = rs("CaseDimW")
  9.     Case4DimW = Trim(Case4DimW)
  10.     Case4DimH = rs("CaseDimH")
  11.     Case4DimH = Trim(Case4DimH)
  12.     Volume4 = rs("Volume")
  13.     Volume4 = Trim(Volume4)
  14.     Weight4 = rs("Weight")
  15.     Weight4 = Trim(Weight4)
  16.  
  17. End if
  18.  
  19.  
I have managed to get the int of a loop into the SQL, but just can't seem to change the string name. Here's what I've tried:
Expand|Select|Wrap|Line Numbers
  1. i = 1
  2. Do
  3.     SQL = "SELECT * FROM tblPackingDetails WHERE ((tblPackingDetails.ShippmentNumber = '"&ShippingNumber&"') AND (tblPackingDetails.CaseNo = '"&i&"'))"
  4.     response.write(SQL)
  5. Set rs = Server.CreateObject("ADODB.Recordset")
  6.  
  7. rs.open SQL, Conn
  8.  if Not rs.EOF Then
  9.     Case1 &i& DimL = rs("CaseDimL")
  10.     Case1+i+DimL = Trim(Case1&i&DimL)
  11.     Case2DimW = rs("CaseDimW")
  12.     Case2DimW = Trim(Case2DimW)
  13.     Case2DimH = rs("CaseDimH")
  14.     Case2DimH = Trim(Case2DimH)
  15.     Volume2 = rs("Volume")
  16.     Volume2 = Trim(Volume2)
  17.     Weight2 = rs("Weight")
  18.     Weight2 = Trim(Weight2)
  19.  
  20.  
  21. End if 
  22. i = i + 1
  23. Loop Until i = 10
Any help would be appreciated,

Pete.
Nov 27 '07 #1
2 1563
Nicodemas
164 Expert 100+
You could use the Execute statement to construct the assignment statement dynamically. The double quotes can be tricky, so watch it.



if Not rs.EOF Then
...execute("Case1" &i& "DimL = rs(""CaseDimL"")")
Nov 28 '07 #2
jhardman
3,406 Expert 2GB
Pete,

I think you should look into using an array or two, I think that would solve your problem, and they are very easy to loop through.

Jared
Nov 30 '07 #3

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

Similar topics

1
by: Ken Fine | last post by:
I have a menu system that has nodes that can be opened or closed. In an effort to make my code more manageable, I programmed a little widget tonight that keeps track of the open/active item and...
1
by: george lewycky | last post by:
Is there someway I can make a parameter or variable of some sort to pass into my PL/SQL cursor shown below to change the value of the date without having to rebuild the package each time?? Can I...
16
by: chris | last post by:
im new to javascript but slowly getting better what i want to do is have some text on the screen and when an event happens for example click a button the text would change to what i want. how...
6
by: utterberg | last post by:
Hi, I've got an xml that looks like this: <section name="Risk"> <label>RISK MANAGEMENT (RM)</label> <field name="RM.1"> <ref>RM.1</ref> <label>Text goes here...</label> <option...
10
by: Altman | last post by:
I have only done a little programming in C++ so I am still learning but I am having a problem with a variable that is changing on me. I have tried this 2 ways with the same result. I have a...
2
by: celtique | last post by:
Hello everybody! I've just registered to this forum and yet got a question. :) I've got some database, that is processed by PHP in a 'while' loop and each element that the loop draws (<li>) gets...
1
by: viceyo | last post by:
Hi! I'm new to Javascript and I'm trying to write a script in which I need to use diferent variable names. The names are used from here: <img border="0" alt="Visit W3Schools!"...
4
by: AMP | last post by:
Hello, I have ArrayLists that are Channel1, Channel 2......Channel16 I want to access them with a (for int s=1;s<17;s++) loop, but I dont know how to do this: "Channel+s" Any help, Thanks Mike
3
TheServant
by: TheServant | last post by:
Hey guys, Basically I have a really big table with lots of variables all over the place. eg. <table> <tr><td><?php echo( $var1." is ".$var2 ); ?></td></tr> <tr><td><?php echo( $bar1." is...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.