Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem using a For, Next and Exit For Statements

Status
Not open for further replies.

NOPOPNOSTYLE

IS-IT--Management
Apr 9, 2002
38
GB
Hi there

I've written some code to check a variable against a scale thats held in a table and pulled back in a recordset, the idea is to loop through the table and exit for when the condition is true, however the code only works when the variables value is lower than the min of the first row of the scale table. I've put the code below, any help would be appreciated.

Lord Exell

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%
VAR_NAME=Request.querystring("ID")
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = "file name=" & Server.MapPath(".") & "\database\udl_managers.udl"
objComm.CommandType = &H0001

'This is Recordset for the Scale
objComm.CommandText = "SELECT * FROM RP_1_MAN_DISC_SCALE"
set RS_SCALE = objComm.Execute

'This is Recordset to determine number of rows in the Scale Currently 5 Rows
objComm.CommandText = "SELECT Count(MAN_DISC_SCALE.ID) AS CountOfID FROM MAN_DISC_SCALE"
set RS_COUNTER = objComm.Execute

'This is Recordset for the Managers Score, currently=2
objComm.CommandText = "SELECT * FROM RP_2_MAN_DISC_AWARD Where PAYROLL_NUM=7728"
set RS_SCORE = objComm.Execute


'assign the Managers Score from RS_SCORE as a variable as there is only 1 row selected from RS_SCORE
VAR_ONE=Cint(RS_SCORE("RP_2_MAN_DIS_AWARD"))'value here is 2

'assign the number from RS_COUNTER as a variable as there is only 1 row selected from RS_COUNTER
VAR_TWO=Cint(RS_COUNTER("CountOfID"))'value here is 5

For I = 1 To VAR_TWO 'VAR_TWO is equal to 5
If VAR_SCORE < RS_SCALE("ZFROM") Then 'values for ZFROM are Row1=1 etc till Row5=5
'If I replace VAR_SCORE in the above line with 0 the code works a number above 0 does not.
VAR_RES=RS_SCALE("PTS") 'values for PTS are double row 2 ie Row1=2 pts till Row5=10 pts
Exit For
End IF
Next
%>
<body>
<%
Response.Write(VAR_RES)
'VAR_RES value should be 4 but the code does not seem to be looping correctly
%>


<%'Response.Write(VAR_ONE)%><br>
<%'Response.Write(VAR_TWO)%><br>
</body>
</html>
<%
Set RS_SCALE = Nothing
Set RS_SCORE = Nothing
Set RS_COUNTER = Nothing
Set objComm = Nothing
%>
 
Code:
If VAR_SCORE < RS_SCALE("ZFROM") Then 'values for ZFROM are Row1=1 etc till Row5=5
Where is VAR_SCORE declared and assigned a value?


Tony
reddot.gif WIDTH=500 HEIGHT=2 VSPACE=3

 
Fester

Thanks for your prompt reply, var_score should be var_one, just being blond How do you get the Code bit up in your reply? I've re put the code below....

Lord Exell

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<html>
<head>
<title>Test</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<%
VAR_NAME=Request.querystring("ID")
Set objComm = Server.CreateObject("ADODB.Command")
objComm.ActiveConnection = "file name=" & Server.MapPath(".") & "\database\udl_managers.udl"
objComm.CommandType = &H0001

'This is Recordset for the Scale
objComm.CommandText = "SELECT * FROM RP_1_MAN_DISC_SCALE"
set RS_SCALE = objComm.Execute

'This is Recordset to determine number of rows in the Scale Currently 5 Rows
objComm.CommandText = "SELECT Count(MAN_DISC_SCALE.ID) AS CountOfID FROM MAN_DISC_SCALE"
set RS_COUNTER = objComm.Execute

'This is Recordset for the Managers Score, currently=2
objComm.CommandText = "SELECT * FROM RP_2_MAN_DISC_AWARD Where PAYROLL_NUM=7728"
set RS_SCORE = objComm.Execute


'assign the Managers Score from RS_SCORE as a variable as there is only 1 row selected from RS_SCORE
VAR_ONE=Cint(RS_SCORE("RP_2_MAN_DIS_AWARD"))'value for VAR_ONE is 2

'assign the number from RS_COUNTER as a variable as there is only 1 row selected from RS_COUNTER
VAR_TWO=Cint(RS_COUNTER("CountOfID"))'value for VAR_TWO is 5

For I = 1 To VAR_TWO 'VAR_TWO is equal to 5
If VAR_ONE < RS_SCALE("ZFROM") Then 'values for ZFROM are Row1=1 etc till Row5=5
'If I replace VAR_ONE in the above line with 0 the code works, a number above 0 does not.
VAR_RES=RS_SCALE("PTS") 'values for PTS are double row 2 ie Row1=2 pts till Row5=10 pts
Exit For
End IF
Next
%>
<body>
<%
Response.Write(VAR_RES)
'VAR_RES value should be 4 but the code does not seem to be looping correctly
%>
</body>
</html>
<%
Set RS_SCALE = Nothing
Set RS_SCORE = Nothing
Set RS_COUNTER = Nothing
Set objComm = Nothing
%>
 
Unfortunately not, one cannot fathom this conundrum out.

LORD EXELL

PS

I'm using access 2000 has that got anything to do with this???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top