argumentum Posted July 14, 2021 Share Posted July 14, 2021 (edited) Global $var_A = "failed" Global $var_B = "failed" Global $var_C = "failed" Global $default = @CRLF ; Null ; "" ; Default Any_A(0) ; this always work Func Any_A($val = $default) If Not($val == $default) Then $var_A = $val EndFunc Any_B(0) ; some times Func Any_B($val = $default) If $val <> $default Then $var_B = $val EndFunc Any_C(0) ; never Func Any_C($val = $default) If Not($val = $default) Then $var_C = $val EndFunc ;~ - $var_A = 0 ;~ - $var_B = failed ;~ - $var_C = failed ConsoleWrite('- $var_A = ' & $var_A & @CRLF) ConsoleWrite('- $var_B = ' & $var_B & @CRLF) ConsoleWrite('- $var_C = ' & $var_C & @CRLF) Should not <> mean != ? Is this a bug, a fact of AutoIt, or just me not understanding it ? Edit: Corrected the example Edited July 14, 2021 by argumentum oops Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Subz Posted July 14, 2021 Share Posted July 14, 2021 Think the issue is you're comparing a string and a number. argumentum 1 Link to comment Share on other sites More sharing options...
water Posted July 14, 2021 Share Posted July 14, 2021 I suggest to use Keyword "Default" to denote a default value not to assign values to Global variables in a function Could you please post a real life example so we can see what you try to achieve? argumentum 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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 More sharing options...
RTFC Posted July 14, 2021 Share Posted July 14, 2021 34 minutes ago, argumentum said: Func Any_C($val = $default) If Not($val = $default) Then $var_B = $val EndFunc $var_B should be $var_C here, no? argumentum 1 My Contributions and Wrappers Spoiler BitMaskSudokuSolver BuildPartitionTable CodeCrypter CodeScanner DigitalDisplay Eigen4AutoIt FAT Suite HighMem MetaCodeFileLibrary OSgrid Pool RdRand SecondDesktop SimulatedAnnealing Xbase I/O Link to comment Share on other sites More sharing options...
Musashi Posted July 14, 2021 Share Posted July 14, 2021 (edited) @argumentum BTW : not a solution, just a typo : [...] Any_C(0) ; never Func Any_C($val = $default) If Not($val = $default) Then $var_B = $val EndFunc [...] If Not($val = $default) Then $var_C = $val -->not : If Not($val = $default) Then $var_B = $val EDIT : Sorry, I had overlooked @RTFC 's post. There he already noted that typo . Edited July 14, 2021 by Musashi argumentum 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
argumentum Posted July 14, 2021 Author Share Posted July 14, 2021 4 hours ago, water said: Could you please post a real life example I corrected the example due to the wrong variable and to set the real life observation that got me to post. The default I was using is @CRLF. The brainstorm for that, is that I wanted to be able to pass a variable in the function to the "keyword Default", as the variable may use it. So is late at night and I'm like "I should use @CRLF as the default, it should be all the same" but @CRLF is way different to zero and <> should have catch that. But if that is so, what have I done since 2005 !!!, OMG !!!, ...I'll post and go to sleep. "" and 0, ok. But @CRLF and 0, c'mon !. I know that an empty string and zero may get interpreted as nothing/zilch/nada, ok, zero. But a string ?. Hence the posting. I've got code to get what I need. The question is, should a ticket be opened or not. Or am I still sleepy, hmm. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Solution Nine Posted July 14, 2021 Solution Share Posted July 14, 2021 Like @Subz already pointed out, it is not a good idea to voluntary compare String and Number. Quote Comparing different datatypes Care is needed if comparing mixed datatypes, as unless the case-sensitive (==) string operator is used, mixed comparisons are usually made numerically. Most strings will be evaluated as 0 and so the result may well not be the one expected. It is recommended to force the items being compared into the same datatype using Number()/String() before the comparison. argumentum 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Nine Posted July 14, 2021 Share Posted July 14, 2021 Here a detailed example how AutoIt works when comparing different datatypes : ; in this block, the string "string" is converted to number 0 ConsoleWrite((0 = "string") & @CRLF) ConsoleWrite((1 = "string") & @CRLF) ConsoleWrite((0 <> "string") & @CRLF & @CRLF) ; in this block, the string "01" is converted to number 1 ConsoleWrite((0 = "01") & @CRLF) ConsoleWrite((1 = "01") & @CRLF) ConsoleWrite((0 <> "01") & @CRLF & @CRLF) ; in this block, the numbers left to the == operator are first converted to number, then reconverted to string because of == op ConsoleWrite((0 == "01") & @CRLF) ConsoleWrite((1 == "01") & @CRLF) ConsoleWrite((01 == "01") & @CRLF) ConsoleWrite((010 == "10") & @CRLF) “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
jchd Posted July 14, 2021 Share Posted July 14, 2021 Right on spot! I've submitted a revision of the help file to clarify that and other points. It shows in the beta help under Language Reference - Datatypes. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
JockoDundee Posted July 14, 2021 Share Posted July 14, 2021 Feeling confident in your understanding? Then Guess the Output! Local $a="abc" If $a=1 Then ConsoleWrite("$a=1" &@CRLF) If Not $a=1 Then ConsoleWrite("Not $a=1" &@CRLF) If Not Not $a=1 Then ConsoleWrite("Not Not $a=1" &@CRLF) Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Nine Posted July 14, 2021 Share Posted July 14, 2021 (edited) First one is easy --> false (because $a will be converted to 0) Second one : Not has highest precedence, so Not $a should return False, so False = 1 --> False Third one is easy if I am right on second --> True ps. my guess on second was right, but I wasn't really sure about it : gj Jocko pss. just googled translation on jocko : it means gaming. You are wearing your name very well ! Edited July 14, 2021 by Nine Skysnake and JockoDundee 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
pseakins Posted July 15, 2021 Share Posted July 15, 2021 17 hours ago, water said: not to assign values to Global variables in a function I would suggest that this is the very reason Global values exist. So that they can be accessed and assigned values from within a function and anywhere else in the program. Help: "A variable's scope is controlled by when and how you declare the variable. If you declare a variable at the start of your script and outside any functions it exists in the global scope and can be read or changed from anywhere in the script." Phil Seakins Link to comment Share on other sites More sharing options...
argumentum Posted July 15, 2021 Author Share Posted July 15, 2021 ...is good advise nonetheless @pseakins. But the point was more along the use of the operators ( <>, =, etc. ). ( is a good read ) So as far as the OP question is concerned, it was satisfactorily answered. Shame on me for not being more of a ... programmer. I script without much thinking, to the point of not even taking datatypes into consideration. Gotta love AutoIt. Is very forgiving Skysnake 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now