473,503 Members | 1,666 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

for x =...next, how to assign variable with the X value?

Hi!

I want, using a form, enter a number and then, read that number of records
in a database and store information in variables. The only way I see to do
this is to do a FOR...NEXT to the number entered in the form, and then
include the database reading into it.

THE PROBLEM:

<%
for x = 1 to [Selected Number]
mySQL = "SELECT * FROM table "
set ObjectRecordset=ObjetConnection.execute(mySQL)
FieldValue = ObjectRecordset.fields("field")
next
%>

With this example, let's say the [Selected Number] is 3, the script will
read the first 3 lines but the variable FieldValue will be overwritten at
each pass of the FOR...NEXT...

So, I would need to use FieldValue1, FieldValue2, FieldValue3. As the
number entered can be anything, I cannot use static variables. I would need
to use the variable FieldValue followed by the value of x...
FieldValue[x]
Then the result should be FieldValue1, FieldValue2, etc... until the number
entered is reached.

Is anybody can give me the way to do this?

Thanks!!!
Andrew
Jul 22 '05 #1
2 2464
Have you thought about using an array?

dim FieldValues([Selected Number])
for x = 1 to ...
... are you REALLY running a database query in every iteration in this
loop????????
FieldValues(x) = whatever
next

--
http://www.aspfaq.com/
(Reverse address to reply.)


"news.cablevision.qc.ca" <no****@nospam.com> wrote in message
news:dv*********************@news20.bellglobal.com ...
Hi!

I want, using a form, enter a number and then, read that number of records
in a database and store information in variables. The only way I see to do this is to do a FOR...NEXT to the number entered in the form, and then
include the database reading into it.

THE PROBLEM:

<%
for x = 1 to [Selected Number]
mySQL = "SELECT * FROM table "
set ObjectRecordset=ObjetConnection.execute(mySQL)
FieldValue = ObjectRecordset.fields("field")
next
%>

With this example, let's say the [Selected Number] is 3, the script will
read the first 3 lines but the variable FieldValue will be overwritten at
each pass of the FOR...NEXT...

So, I would need to use FieldValue1, FieldValue2, FieldValue3. As the
number entered can be anything, I cannot use static variables. I would need to use the variable FieldValue followed by the value of x...
FieldValue[x]
Then the result should be FieldValue1, FieldValue2, etc... until the number entered is reached.

Is anybody can give me the way to do this?

Thanks!!!
Andrew

Jul 22 '05 #2
On Wed, 1 Dec 2004 10:30:48 -0500, "news.cablevision.qc.ca"
<no****@nospam.com> wrote:
Hi!

I want, using a form, enter a number and then, read that number of records
in a database and store information in variables. The only way I see to do
this is to do a FOR...NEXT to the number entered in the form, and then
include the database reading into it.

THE PROBLEM:

<%
for x = 1 to [Selected Number]
mySQL = "SELECT * FROM table "
set ObjectRecordset=ObjetConnection.execute(mySQL)
FieldValue = ObjectRecordset.fields("field")
next
%>

With this example, let's say the [Selected Number] is 3, the script will
read the first 3 lines but the variable FieldValue will be overwritten at
each pass of the FOR...NEXT...

So, I would need to use FieldValue1, FieldValue2, FieldValue3. As the
number entered can be anything, I cannot use static variables. I would need
to use the variable FieldValue followed by the value of x...
FieldValue[x]
Then the result should be FieldValue1, FieldValue2, etc... until the number
entered is reached.

Is anybody can give me the way to do this?


Bleh! Return only relevant records, you can use the TOP query in some
databases, or loop through the first records of your recordset.
Whatever you do, issuing the same query three times in a loop is
wasteful. Basically, you query the dataabse to return every single
record, then select a single value out of all those, then repeat two
more times. Learn to use a WHERE clause.

Jeff
Jul 22 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
8365
by: Mike | last post by:
Is there any way I can use a function to create a variable and assign a value to it? I have a Perl script that returns some LDAP information: sn=Shore givenname=Mike logintime=20041008153445Z...
25
4306
by: Rim | last post by:
Hi, I have been thinking about how to overload the assign operation '='. In many cases, I wanted to provide users of my packages a natural interface to the extended built-in types I created for...
2
8318
by: Matt | last post by:
If I assign VBScript server side variable a to javascript variable x, it is fine. <% Dim a, b a = 10 %> var x = <%= a %>; alert(x); But if I do the other way around, then it has 500 error....
4
8978
by: Terry | last post by:
I have a number of input boxes used to display totals based on selected items for each row in a table. There are more than a few rows that are identical, except for the form field name. I have...
4
12540
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
1
11254
by: Roger Oshaug | last post by:
How would I assign the MAX(value) in a tablecolumn to an Integer variable, or put another way, assign any value from a table record to a variable? I am trying to achieve something like this: ...
2
6227
by: Jim McGivney | last post by:
In asp 2.0 I am trying to insert a row using a detailsview control connected to an accessDataSource. I get the error message below. I am having trouble identifing which data field is causing the...
6
4078
by: Don Lancaster | last post by:
I need to progrmatically do this inside a loop this.fh03.value = fixFloat (Harms, numPoints) ; with the numbers changing per an index. If I try curHvals = "03" ; // (derived from...
2
3135
by: Birky | last post by:
Assign the output of a select to a variable? I am unable to find a way to assign the results of an SQL statement to a variable. I know how to assign the SQL statement to a variable but again no...
0
7203
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7281
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7334
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6993
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7462
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5579
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4675
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1514
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.