Jump to content

1 and string = bug?


Recommended Posts

I think the best thing to do is convert the entire "string" to a string.

$s = String($s)

And then run the statement from there with StringIsDigit and so on...

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

I guess I still have a problem with this ...

It should not matter (Boolean wise) how the string is arranged. Why does the 2nd string fail? (for me it does)

$s = '1 String'
If $s = 1 Then
    MsgBox(0,'1st','True');<---
Else
    MsgBox(0,'1st','False')
EndIf

; swap string
$s = 'String 1'
If $s = 1 Then
    MsgBox(0,'2nd','True')
Else
    MsgBox(0,'2nd','False');<---
EndIf

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

I guess I still have a problem with this ...

It should not matter (Boolean wise) how the string is arranged. Why does the 2nd string fail? (for me it does)

$s = '1 String'
If $s = 1 Then
    MsgBox(0,'1st','True');<---
Else
    MsgBox(0,'1st','False')
EndIf

; swap string
$s = 'String 1'
If $s = 1 Then
    MsgBox(0,'2nd','True')
Else
    MsgBox(0,'2nd','False');<---
EndIf

I retract my statement on the numbers appearing at the end of the string... I must've been smoking something good when I typed that up. It seems to only get the numbers prior to the alpha characters, and drops everything after it.
Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Link to comment
Share on other sites

As explained previously, when comparing a string to a number, the string is converted to a number. When converting a string to a number it will convert the string starting at the first character until it finds a character that isn't a number. So, a string containing "123456String78" will convert to 123456. In your second example it doesn't find any numbers before it finds a character that isn't a number (or a space), so it returns 0 which doesn't equal 1.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

BrewManNH,

That is the best explanation I've heard so far as to what the reactions are in a statement like that.

thanks

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
Share on other sites

To verify how AutoIt converts a string to a number use function "Number":

ConsoleWrite(number("123456String78") & @LF)
displays 123456.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

In your second example it doesn't find any numbers before it finds a character that isn't a number (or a space)

I have to correct/expand upon one point in my statement above to avoid confusion. The spaces that are ignored are the ones that start off the string, not any that are contained within the string. Example, " 123456String789" is converted to 123456 because the leading spaces are ignored. " 1234 56String789" gets converted to 1234 because the space after the 4 ends the conversion.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...