Strange number bug

Results 1 to 3 of 3

Thread: Strange number bug

  1. #1
    Join Date
    Dec 1969

    Default Strange number bug

    My page counts postage like this:<BR><BR>&#060;%<BR><BR>If Instr(CCcart(CC_Format,i), "12") OR Instr(CCcart(CC_Format,i), "LP") OR Instr(CCcart(CC_Format,i), "BOX")_<BR>OR Instr(CCcart(CC_Format,i), "10") then &#039;Tilaaviev├Ąt maksavat 7<BR>CCcart_Shipping="7"<BR>else CCcart_Shipping = CCcart_Shipping<BR>END IF<BR><BR>If CCcart_Shipping &#060;&#062; "7" then<BR>IF Instr(CCcart(CC_Format,i), "7") OR Instr(CCcart(CC_Format,i), "Misc") OR Instr(CCcart(CC_Format,i), "VIDEO") OR Instr(CCcart(CC_Format,i), "Mag")_<BR>OR Instr(CCcart(CC_Format,i), "BOOK") then<BR>CCcart_Shipping="5.30"<BR>end if<BR>else CCcart_Shipping = CCcart_Shipping<BR>END IF<BR><BR>If CCcart_NumItems &#062; "5" then<BR>CCcart_Shipping="7"<BR>else CCcart_Shipping = CCcart_Shipping<BR>END IF<BR><BR>If CCcart_Shipping &#060;&#062; "7" then <BR>IF CCcart_NumItems = "3" or CCcart_NumItems = "4" or CCcart_NumItems = "5" then <BR>CCcart_Shipping="5.30"<BR>END IF<BR>else CCcart_Shipping = CCcart_Shipping<BR>END IF<BR><BR>If CCcart_Shipping &#060;&#062; "7" and CCcart_Shipping &#060;&#062; "5.30" then<BR>IF CCcart_NumItems = "2" or CCcart_NumItems = "1" then<BR>CCcart_Shipping="4.40"<BR>END IF<BR>else CCcart_Shipping = CCcart_Shipping<BR>END IF<BR><BR>%&#062;<BR><BR>But when the cart has an order which value is very much (about 200 or over) the postage becomes 0. Why?

  2. #2
    Join Date
    Dec 1969

    Default RE: Strange number bug

    Make a variable as a "Counter", and one to hold a True/False<BR><BR>Dim myCount, MyIF<BR>myCount = 0<BR>MyIF = True<BR>Then Just before each "IF statement" add 1 to the counter.<BR><BR>ie<BR>myCount = myCount + 1<BR><BR>IF ... Then<BR>MyIF = True<BR>Else<BR>MyIF = False<BR>END IF<BR><BR>Then Write out the info, And write out all values of every variable (So you can see what its doing & going wrong...)<BR><BR>Response.Write "This is IF statement #" & myCount & " The part of the IF we ran was " & MyIF & "&#060;/br&#062;"<BR>Response.Write "All the varaibles that might change in statement"<BR><BR>This will tell you which statement it is. Weather it was the IF or the ELSE side that executed.<BR>Also<BR>By writing out all variables so you can see how they change with each part of your code...<BR>then something might jump out at you as to where and what is causeing the Problem...<BR><BR>Also<BR>You should not be comparing String values when it should be integers...<BR><BR>If CCcart_Shipping &#060;&#062; "7" then <BR>IF CCcart_NumItems = "3" or CCcart_NumItems = "4" or CCcart_NumItems = "5" then <BR>CCcart_Shipping="5.30"<BR>END IF<BR><BR>Any number in quotes "100" &#060;&#060;is a String value... <BR>CCcart_Shipping="5.30" &#060;&#060;&#060;string value<BR>CCcart_Shipping=5.30 &#060;&#060;&#060; is numerical<BR><BR>Yes, most of the time vbs is smart enough to convert if doing math...<BR>myTest = "100", MyTest2 = 100<BR>myTest + myTest2 = 200 &#060;&#060;it will convert and do the addition...<BR><BR>But anything else<BR>IF myTest &#060;&#062; MyTest 2 Then<BR>Well you are directly comparing a String DataType to a numerical Datatype<BR><BR>[This might not give the comparison you might expect]<BR><BR>*I Could be wrong*<BR>But if comparing 2 different datatypes, it can be finicky sometimes...<BR><BR>But debug, and try to locate the problem area 1st.<BR>

  3. #3
    Join Date
    Dec 1969

    Default Well, that code has enough problems...

    ...that I don&#039;t really want to try and figure out what the exact problem is.<BR><BR>Can we try rewriting the code, instead???<BR><BR>And can I please ask what the point of all those lines that do<BR> else CCcart_Shipping = CCcart_Shipping<BR>is??? They aren&#039;t *DOING* anything at all.<BR><BR>&#060;%<BR>&#039; do these JUST ONCE!<BR>fmt = CCcart(CC_format,i)<BR>qty = CLNG( CCart_NumItems )<BR><BR>If Instr(fmt, "12")&#062;0 OR Instr(fmt, "LP")&#062;0 OR Instr(fmt, "BOX")&#062;0 OR Instr(fmt, "10")&#062;0 THEN<BR> CCcart_Shipping = 7.00<BR><BR>ELSEIF Instr(fmt, "7")&#062;0 OR Instr(fmt, "Misc")&#062;0 OR Instr(fmt, "VIDEO")&#062;0 _<BR> OR Instr(fmt, "Mag")&#062;0 OR Instr(fmt, "BOOK")&#062;0 _<BR>THEN<BR> CCcart_Shipping = 5.30<BR><BR>ELSEIF qty &#062; 5 then<BR> CCcart_Shipping = 7.00<BR><BR>ELSEIF qty = 3 OR qty = 4 OR qty = 5 THEN<BR> CCcart_Shipping = 5.30<BR><BR>ELSEIF qty = 2 OR qty = 1 THEN<BR> CCcart_Shipping = 4.40<BR><BR>END IF<BR>%&#062;<BR><BR>WHY would you use quotes around things that are *NUMBERs*????<BR><BR>And apparently you don&#039;t realize the INSTR returns the *position* in the string, as an integer. Or that the keyword OR, when presented with integers (all you INSTR expressions), does a BITWISE OR. You need to give it boolean values (hence my &#062;0 codings) to make it do a boolean OR.<BR><BR>But quite frankly, I see *NOTHING* in that code that assigns a CCcart_Shipping value when the quantity is even simply 6 or greater!<BR><BR>So if the shipment doesn&#039;t match one of the INSTR tests, and the quantity is 6 or more...??? Do you see anything that will give it a shipping cost??<BR><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