RichardL Posted April 9, 2013 Share Posted April 9, 2013 (edited) I was using AutoIt to make occasional test values for another app. So I had an array of some new values that needed action, and some blanks. Then I realised that zero was not being actioned, and the problem is this test gives true. $x = 0 If $x = "" Then ConsoleWrite("Blank ") EndIf So I tried the opposite and that gives true as well. $x = "" If $x = 0 Then ConsoleWrite("Zero ") EndIf So is "" identical to 0? but it can't be because Number() can see the difference? Is this a fault? Or just needs a warning in the help? I looked at the data-types help, but didn't see a clear warning about this. ? Edited April 10, 2013 by RichardL Link to comment Share on other sites More sharing options...
water Posted April 10, 2013 Share Posted April 10, 2013 Please check the description of datatypes in the help file.This sentence describes what's going on: "If a string is used as a number, an implicit call to Number() function is done. So if it doesn't contain a valid number, it will be assumed to equal 0." My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
BrewManNH Posted April 10, 2013 Share Posted April 10, 2013 Empty strings, and any string that can't be converted to a number, is going to equal to zero. 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 GudeHow 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 More sharing options...
water Posted April 10, 2013 Share Posted April 10, 2013 AutoIt uses Number() internally so the following comparison is being done: If 0 = 0 Then ... My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
RichardL Posted April 10, 2013 Author Share Posted April 10, 2013 Yes, both your replies explain the second example. In the first, is the comparison done as a number or string? The result implies that "" is converted to 0 so the result is true. Link to comment Share on other sites More sharing options...
BrewManNH Posted April 10, 2013 Share Posted April 10, 2013 No, it explains both examples because they're identical...you're comparing a string to a number in both, just because the 2 are on opposite sides of the comparison makes no difference. "" = 0 and 0 = "" 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 GudeHow 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 More sharing options...
czardas Posted April 10, 2013 Share Posted April 10, 2013 (edited) Have you tried this? $x = 0 If $x == "" Then ConsoleWrite("Blank ") EndIf $x = "" If $x == 0 Then ConsoleWrite("Zero ") EndIf Edited April 10, 2013 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
AZJIO Posted April 10, 2013 Share Posted April 10, 2013 Have you tried this? $x = 0 ConsoleWrite('>|' & $x & '|<' &@LF) ConsoleWrite(VarGetType($x) &@LF) $x = "" ConsoleWrite('>|' & $x & '|<' &@LF) ConsoleWrite(VarGetType($x) &@LF) My other projects or all Link to comment Share on other sites More sharing options...
RichardL Posted April 10, 2013 Author Share Posted April 10, 2013 Tried both examples - use == to force string comparison, use VarGetType to test number/string. Thanks. Link to comment Share on other sites More sharing options...
guinness Posted April 11, 2013 Share Posted April 11, 2013 Or IsNumber and IsString. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
AZJIO Posted April 11, 2013 Share Posted April 11, 2013 Usually the type of data is known. If function returns 0, won't come to mind to compare it with a line. Think about what type of data the variable can store. In most cases, this solves the problem. If the array contains different data types and is compared in the loop as equivalent data, then it's the wrong coding. My other projects or all Link to comment Share on other sites More sharing options...
RichardL Posted April 11, 2013 Author Share Posted April 11, 2013 Not quite equivalent data, either a new numeric value or a string blank to indicate not to transfer the value. A cheap trick to avoid adding an array of flags and passing that along with the array of values. Link to comment Share on other sites More sharing options...
jchd Posted April 11, 2013 Share Posted April 11, 2013 If you use the beta you can assign the keyword Null to a variable. The semantic being "this variable has not been assigned a meaningfull value". Then after function return you can test for the variable being == Null 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...
AZJIO Posted April 11, 2013 Share Posted April 11, 2013 (edited) expandcollapse popup#include <Array.au3> Local $a[100] For $i = 0 To 99 $tmp = Random(0, 8, 1) If $tmp = 5 Then $tmp = '' $a[$i] = $tmp Next ; _ArrayDisplay($a, 'Array') Local $b[100] $timer1 = TimerInit() $j = 0 For $i = 0 To 99 If $a[$i] Or $a[$i]=='0' Then ; faster $b[$j] = $a[$i] $j+=1 EndIf Next $timer1 = TimerDiff($timer1) ReDim $b[$j] Local $c[100] $timer2 = TimerInit() $j = 0 For $i = 0 To 99 If Not($a[$i]=='0') Then ; slower $c[$j] = $a[$i] $j+=1 EndIf Next $timer2 = TimerDiff($timer2) ReDim $c[$j] _ArrayDisplay($b, 'Array') ; _ArrayDisplay($c, 'Array') MsgBox(0, "Res", _ 'Time1 : ' & Round($timer1, 2) & ' msec' &@LF& _ 'Time2 : ' & Round($timer2, 2) & ' msec') Edited April 11, 2013 by AZJIO My other projects or all 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