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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

looping problem 1

Status
Not open for further replies.

jordan11

Technical User
May 24, 2003
150
GB
Hi,
I am having a looping problem. I have a loop that first checks for each clientid and then does a calculations for evey clientid one of these calculations require a loop.
The problem I am having is the first clientid calculations are done correctly but anything after that gives the same results and the calculation that is in the loop only give a result for the first calculation and then gives 0 for all the rest of the clientid.

This the output of my results

1 clientid
0
825
1
20
30
750
390 calaculation that uses loop
12.5
1965 total results


2 clientid
0
825
1
20
30
750
0 calaculation that uses loop
12.5
1575 total



5 clientid
0
825
1
20
30
750
0 calaculation that uses loop
12.5
1575 total



7 clientid
0
825
1
20
30
750
0 calaculation that uses loop
12.5
1575 total

as you can see my results are not changing but the clientid is.

This my code

Do while not oRScp.EOF

StropportunityID = oRScp("opportunityId")

response.write StropportunityID & "<br>"



geography=0

if StrlocationState = PreferredState then
geography = geography + 10
end if



if StrlocationState = StateBirth then
geography = geography + 40
end if

if StrlocationState = medstate then
geography = geography + 60
end if

'response.write geography & "<br>"
'response.end

if StrlocationState = l_states then
geography = geography + 10
end if



geography=geography*30

response.write geography & "<br>"
'response.end


qualifications=0

if medstate="INT" then

qualifications=qualifications+(strIMG*10)
ELSE
qualifications=qualifications+ (strAMG *10)
end if

if C_Status = "Residents" then
qualifications=qualifications(strRESGRAD*5)
end if

if C_Status = "Fellow" then
qualifications=qualifications+(strRESGRAD*5)
end if


if C_Status = "Military" then
qualifications=qualifications+(strPRACHY*5)
end if


if pBoardStatus = BoardStatus then
qualifications=qualifications+ 10
end if



if StrlocationState = l_states then
qualifications=qualifications+ 15
end if

qualifications=qualifications*15
response.write qualifications & "<br>"
'response.end


IF paytype =1 then
p_min=p_min*2080
end if
IF paytype =1 then
p_max=p_max*2080
end if

IF strsalarytype = 1 then
o_min=o_min*2080
END IF
IF strsalarytype = 1 then
o_max=o_max*2080
end if


response.write strsalarytype & "<br>"
'response.write o_min & "<br>"
'response.write o_max & "<br>"
'response.write paytype & "<br>"
'response.write p_min & "<br>"
'response.write p_max & "<br>"




salary=0
salcal=0

salcal=((p_min - o_min)/o_min)*100
'response.write o_min & "<br>"
'response.write p_min & "<br>"
'response.write salcal


if salcal >=0 and salcal <=10 then
salary="100"
elseif salcal >=11 and salcal <=20 then
salary="80"
elseif salcal >=21 and salcal <= 30 then
salary="70"
elseif salcal >=31 and salcal <= 70 then
salary="40"
else salary="20"

end if
response.write salary & "<br>"
'response.end

salary1=0
salcal2=0
salcal2=(p_max - o_max)/o_max *100

'response.write o_max & "<br>"
'response.write p_max & "<br>"
'response.write salcal2


if salcal >=0 and salcal <=10 then
salary1="100"
elseif salcal >=11 and salcal <=20 then
salary1="80"
elseif salcal >=21 and salcal <= 30 then
salary1="60"
elseif salcalsalcal >=31 and salcal <= 40 then
salary1="20"
else salary1=30

end if
response.write salary1 & "<br>"
'response.end



tsalary=CDbl(salary)+CDbl(salary1)
'response.write salary& "<br>"
'response.write salary1& "<br>"
'response.write tsalary& "<br>"
tsalary=CDbl(tsalary)*15

response.write tsalary & "<br>"
'response.end



QUESTIONS=0
DO While not rt.EOF
o_questionid=p_questionid
if O_questionID = P_questionID then
questions=questions+2
else
questions =questions
end if
rt.movenext
loop

QUESTIONS=QUESTIONS*15

response.write questions & "<br>"
'response.end

lifestyle=0
if strclakes = 1 then
lifestyle=lifestyle+(strlakes*2.5)
end if

if strcdine = 2 then
lifestyle=lifestyle+(strdine*2.5)
end if


if strcart = 4 then
lifestyle=lifestyle+(strart*2.5)
end if


if strcairport = 8 then
lifestyle=lifestyle+(strairport*2.5)
end if




lifestyle=lifestyle*15
response.write lifestyle & "<br>"
'response.end

rating=cint(QUESTIONS)+cint(tsalary)+cint(qualifications)+cint(lifestyle)+cint(geography)

RESPONSE.WRITE RATING & "<br>"

txtsql ="INSERT INTO rating (opportunityid,physicianID,rating)values ('" & StropportunityID & "','" & strphysicianid &"', '" & rating & "')"
conn.Execute txtsql

'RESPONSE.End
'rt.Close(how to comment this out for the 2nd loop to work)
'Set rt= nothing
oRScp.movenext
loop

set oRScp = nothing
set conn = nothing
 


Do you mean this loop:

Code:
QUESTIONS=0
      DO While not rt.EOF
    o_questionid=p_questionid
    if O_questionID = P_questionID then
        questions=questions+2
     else
       questions =questions
    end if
        rt.movenext
      loop
    
    QUESTIONS=QUESTIONS*15

if so, then where do you set rt ? it is not inside your main loop using oRScp recordset object. It seems that it is set outside the main loop, therefore when you first run the inner loop using rt it will go through the records from the BOF (Beginning Of the File) to the EOF (End Of the File), then on any further evaluations (next iteration of your main loop), it will already be at the EOF marker.

If you want to use the same records from rt, then before you start the loop use: rt.movefirst otherwise set the rt recordset object inside the main loop, so that it gets reset on each iteration.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
its very difficult to see where in your code actually the value is being reset to 0...

i would suggest you to track the calculated field at every step by doing the response.write and see where actually it is going back to 0

-DNG
 

DNG - I'd agree with you there - it is very non-descriptive and difficult to read.. my post was, at best, an educated guess as to what/where the problem might be - I'll be lucky if it's right!

jordan11 - It is always better to be clear and concise about your problem, otherwise we find it very difficult to identify what it is wrong. It is also very good practice to comment your code to describe what is doing what and why - this helps you to support it in the future, and for other developers to understand what is being done quickly and easily.

Just a bit of friendly advice, as it will make your life much easier !

Anyway - did the suggestion in my last post work ok ?

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Thanks damber that solved one of my problems as now I have results for that part of the loop.

The problem now is the results are not changing, so although the clientid is changing they all have the same results.
My output

1 clientid
0
825
1
20
30
750
390
187.5
2153



2 clientid
0
825
1
20
30
750
390
187.5
2153

5 clientid
0
825
1
20
30
750
390
187.5
2153




7 clientid
0
825
1
20
30
750
390
187.5
2153


Thanks

 
The problrm now is in the main loop

Do while not oRScp.EOF
StropportunityID = oRScp("opportunityId")
calculations are done here
oRScp.movenext
loop

set oRScp = nothing
set conn = nothing

Thanks for the advice
 

I don't see where you use the data from the recordset in the main loop - the calculations seem to be based on variables that always start from 0 and do not have any other info changed during the loop... are they set outside of the loop ?

A smile is worth a thousand kind words. So smile, it's easy! :)
 
yes all my varibles are set outside the loop, I will put them inside the loop and hopefully that will work.

Thanks
 

no problem, glad it worked out for you.

A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top