I have no clue what went wrong?

Results 1 to 3 of 3

Thread: I have no clue what went wrong?

  1. #1
    Ginola Guest

    Default I have no clue what went wrong?

    It has taken me a while trying to figure out why it didn&#039;t work as expect. I still don&#039;t know why? I cut down majority of the script and realised this line doesn&#039;t work as I want it to be.<BR>My idea is to get the min value of two numbers. I&#039;ve searched and can&#039;t find the min function from VBScript.<BR><BR><BR>strcontracts="SELECT * FROM ortable"<BR>Set objRS=Server.CreateObject("ADODB.Recordset")<BR>ob jRS.Open strcontracts,oConn,,adLockOptimistic,adCmdText<BR> location=objRS.getrows<BR>numbercols=ubound(locati on,1)<BR>numberrows=ubound(location,2)<BR>qantity= 20<BR>&#039;the line below serve the debug purpose to ensure qantity has a value of 20<BR>response.write "qantity before loop=" & qantity & "<BR>"<BR>contractdone=0<BR> I=0<BR>&#039;the line below is to ensure I have a right number to compare with qantity<BR>response.write "location(8,0) before loop=" & location(8,I) & "<BR>"<BR> Do while (I&#060;=numberrows and qantity&#062;0)<BR> If qantity&#062;=location(8,I) then<BR> contractdone=location(8,I)<BR> response.write "If has been processed<BR>"<BR> Else<BR> contractdone=qantity<BR> response.write "Else has been processed<BR>"<BR> End If<BR>response.write "contractdone per lot=" & contractdone & "<BR>"<BR> For J=0 to numbercols<BR> response.write location(J,I) & "::"<BR> Next<BR> qantity=qantity-contractdone <BR> I=I+1<BR> Loop<BR>response.write "no.of time=" & I & " and qantity=" & qantity & "contractdone=" & contractdone & <BR><BR>"<BR>"<BR>End If<BR><BR>The output is as follows:<BR>1 the counter check<BR>qantity before loop=20<BR>location(8,0) before loop=25<BR>If has been processed<BR>contractdone per lot=25<BR>58::3::1::0::2025::0::OB::24/05/01::25::no.of time=1 and qantity=-5contractdone=25<BR><BR>What I don&#039;t understand is variable of qantity is 20 and variable location(8,0) is 25. <BR>The conditional statement still execute the &#039;If statement" instead of the &#039;Else statement&#039; as you can see from the output. Any suggestion of what went wrong is very appreciated.<BR><BR>Regards<BR>

  2. #2
    Join Date
    Dec 1969

    Default Only thing I can think of...

    ...is that the datatype of field location(8,0) is *not* a number, so some other kind of comparison is taking place?<BR><BR>Try replacing <BR>&nbsp; &nbsp; If qantity&#062;=location(8,I) then <BR>with<BR>&nbsp; &nbsp; If qantity &#062;= CLng( location(8,I) ) then <BR>to force it to be a number.<BR><BR>If you are curious, you might add in<BR>&nbsp; &nbsp; Response.Write "TypeName of location(8,0) is " & TypeName(location(8,0)) & "&lt;BR&#062;"<BR>just before the "IF" test.<BR><BR>

  3. #3
    Ginola Guest

    Default RE: This is weird...

    Bill<BR><BR>Thanks for you comment. I tried that and it still doesn&#039;t work. However, I&#039;ve replaced <BR>If qantity&#062;=location(8,I) then <BR>by<BR>If clng(qantity)&#062;=Clng(location(8,I)) then<BR>It works finally.<BR><BR>The datatype of location(8,I) is Long as set up in the database.<BR>I&#039;m at a loss to why the comparison result is always executed by the &#039;IF&#039; statement, irregardless of what value I input to the <BR>variable qantity.<BR><BR>Anyway, many thanks for the debugging tips.<BR><BR>Regards<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts