Sign in to follow this  
Followers 0
DickG

Problem with "<="

5 posts in this topic

I just discovered a little problem with a simple "If x <= y" thing.

If I use a number less than "100000" for $Value, it detects whether it is less than or greater than 30,000. It works right up to 99999. As soon as I use "100000", it thinks it is less than 30,000.

I can't find any error in my code, but who knows. I'm no expert.

The test code follows:

============================

Dim $Value, $Value_Calc, $Result

#cs

If I use a value below 100,000, it works fine. At 100,000 or higher is viewed as

though it were less than 30,000.

#ce

$Value = "100000"

MsgBox(0, "$Value", "$Value = " & $Value)

If $Value <= "30000" Then

$Value_Calc = $Value

$Result = FormatCurrency ($Value_Calc)

MsgBox(0, "Test 1A", "Result = " & $Result)

Else

$Value_Calc = "30000"

$Result = FormatCurrency ($Value_Calc)

MsgBox(0, "Test 1B", "Result = " & $Result)

EndIf

#region: Format Currency

Func FormatCurrency ($Number)

Dim $Hold, $dll, $GCF

$Hold=""

$dll=DllOpen("kernel32.dll")

$GCF=DllCall($dll,"int","GetCurrencyFormat","int",0,"int",0,"str", $Number,"int",0,"str",$Hold,"int",20)

DllClose($dll)

$Result = $GCF[5]

Return $Result

EndFunc

#endregion

============================

Thanks,

Dick

Share this post


Link to post
Share on other sites



Make sure you are doing numeric comparisons, note no quotes arround 30000

Number($Value) <= 30000oÝ÷ ÚðéÜ­æ­z{¦z¸½ªâi¹^±«­¢+ØÀÌØíY±ÕôÄÀÀÀÀÀ

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

I just discovered a little problem with a simple "If x <= y" thing.

If I use a number less than "100000" for $Value, it detects whether it is less than or greater than 30,000. It works right up to 99999. As soon as I use "100000", it thinks it is less than 30,000.

I can't find any error in my code, but who knows. I'm no expert.

The test code follows:

============================

Dim $Value, $Value_Calc, $Result

#cs

If I use a value below 100,000, it works fine. At 100,000 or higher is viewed as

though it were less than 30,000.

#ce

$Value = "100000"

MsgBox(0, "$Value", "$Value = " & $Value)

If $Value <= "30000" Then

$Value_Calc = $Value

$Result = FormatCurrency ($Value_Calc)

MsgBox(0, "Test 1A", "Result = " & $Result)

Else

$Value_Calc = "30000"

$Result = FormatCurrency ($Value_Calc)

MsgBox(0, "Test 1B", "Result = " & $Result)

EndIf

#region: Format Currency

Func FormatCurrency ($Number)

Dim $Hold, $dll, $GCF

$Hold=""

$dll=DllOpen("kernel32.dll")

$GCF=DllCall($dll,"int","GetCurrencyFormat","int",0,"int",0,"str", $Number,"int",0,"str",$Hold,"int",20)

DllClose($dll)

$Result = $GCF[5]

Return $Result

EndFunc

#endregion

============================

Thanks,

Dick

You are confusing the comparison of text with the comparison of numbers.

When comparing text text strings if the first character is less then the whole string is less e.g. "1" is less than "3'"

Example

$sString1 = "100"
$sString2 = "30"

$iNumber1 = 100
$iNumber2 = 30

If $sString1 <= $sString2 Then
    $msg = "$String1 '" & $sString1 & "' is less than or equal to '" & $sString2 & "'"
Else
    $msg = "$String1 '" & $sString1 & "' is greater than '" & $sString2 & "'"
EndIf
MsgBox(0,"Text Comparison",$msg)

If $iNumber1 <= $iNumber2 Then
    $msg = "$iNumber1 " & $iNumber1 & " is less than or equal to " & $iNumber2
Else
    $msg = "$iNumber1 " & $iNumber1 & " is greater than " & $iNumber2
EndIf
MsgBox(0,"Number Comparison",$msg)
Edited by Bowmore

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Oh man, I knew it was something simple!

Yes, it works correctly now! Thanks much, guys.

Dick

You are confusing the comparison of text with the comparison of numbers.

When comparing text text strings if the first character is less then the whole string is less e.g. "1" is less than "3'"

Example

$sString1 = "100"
$sString2 = "30"

$iNumber1 = 100
$iNumber2 = 30

If $sString1 <= $sString2 Then
    $msg = "$String1 '" & $sString1 & "' is less than or equal to '" & $sString2 & "'"
Else
    $msg = "$String1 '" & $sString1 & "' is greater than '" & $sString2 & "'"
EndIf
MsgBox(0,"Text Comparison",$msg)

If $iNumber1 <= $iNumber2 Then
    $msg = "$iNumber1 " & $iNumber1 & " is less than or equal to " & $iNumber2
Else
    $msg = "$iNumber1 " & $iNumber1 & " is greater than " & $iNumber2
EndIf
MsgBox(0,"Number Comparison",$msg)

Share this post


Link to post
Share on other sites

Oh man, I knew it was something simple!

Yes, it works correctly now! Thanks much, guys.

Dick

Happy to help.

Whilst AutoIt's use of the Variant data type means you don't have to worry about what the data is most of the time, it can catch you out occasionally in situations like this one until you get used to it. :)


"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0