viewpoint-particle

Author Topic: Number not evaluating as expected  (Read 2808 times)

1bosborn

  • Newbie
  • *
  • Posts: 7
Number not evaluating as expected
« on: October 03, 2014, 10:34:55 am »
Here is an excerpt from my script:
   gross = ItemExtract(4, inline, @Tab)
   faxno = ""
   If gross >= '15000' Then category = 'A'
   If gross >= '5000' && gross <= '14999' Then category = 'B'
   If gross >= '1000' && gross <= '4999' Then Category = 'C'
The gross for the item in question is 49,241.15. The first and second If statements return true and false respectively as expected but the 3rd one also returns true making the category for the item "C" rather that the "A" it should be. Any thoughts on why 49,241.15 would evaluate between 1000 and 4999?
For diagnostic purposes, I modified the code to:
   gross = ItemExtract(4, inline, @Tab)
   faxno = ""
   If gross >= '15000' Then category = 'A' ;this came back true (expected)
   If gross >= '5000'                      ;this came back false (Unexpected)
      If gross <= '14999' Then category = 'B' ;this was skipped
   EndIf
   If gross >= '1000'                      ;this cam back true (expected)
      If gross <= '4999' Then category = 'C'  ;this came back true (unexpected)
   EndIf
I have included comments as to how each evaluated

JTaylor

  • Pundit
  • *****
  • Posts: 914
    • Data & Stuff Inc.
Re: Number not evaluating as expected
« Reply #1 on: October 03, 2014, 10:56:22 am »
You are treating them as text rather than numbers and a comma is lower on the ASCII chart than a 9 so 49,241.15 is less than 4999 but greater than 1000.

Jim

1bosborn

  • Newbie
  • *
  • Posts: 7
Re: Number not evaluating as expected
« Reply #2 on: October 03, 2014, 11:19:43 am »
Interesting, thank you so much for the prompt reply. How do I stop treating it as text and make it a number, remove the comma? And if I were to put a comma into the "text" I am evaluating against would you think it would work as expected?

td

  • Tech Support
  • *****
  • Posts: 2566
    • WinBatch
Re: Number not evaluating as expected
« Reply #3 on: October 03, 2014, 01:03:27 pm »
User StrClean

Code: Winbatch
  gross=StrClean( gross, ", ", "", 0, 1)

to remove comas and get rid of the single quotes around your numeric literals. 
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


JTaylor

  • Pundit
  • *****
  • Posts: 914
    • Data & Stuff Inc.
Re: Number not evaluating as expected
« Reply #4 on: October 03, 2014, 06:45:57 pm »
Commas will not work in "numbers".

Jim

snowsnowsnow

  • Full Member
  • ***
  • Posts: 244
Re: Number not evaluating as expected
« Reply #5 on: October 03, 2014, 11:18:17 pm »
As a matter of style, I'd use SWITCH instead of a series of IF statements.

Try this code:

; vim:fo-=t fo+=ro1 comments+=b\:;
IntControl(50,0,0,0,0)      ; Turn off Web Page Support

Prog = IntControl(1004,0,0,0,0)
gross = "15,123.45"

:loop
gross = AskLine(Prog,"Enter value for Gross:",gross)
cleanGross = StrClean(gross, ", ", "", 0, 1)
SWITCH 1
CASE cleanGross >= 15000
    category = 'A'
    Break
CASE cleanGross >= 5000
    category = 'B'
    Break
CASE cleanGross >= 1000
    category = 'C'
    Break
CASE 1
    category = 'None'
ENDSWITCH
Pause("cleanGross = %cleanGross%",category)
goto loop