dRsrb Posted April 8, 2009 Posted April 8, 2009 (edited) Hello! I have two general problems which I don't understand: #include <array.au3> _1_Array_Problem() _2_If_Problem() Func _1_Array_Problem() Local $aTest[3] $aTest[0] = 'Test' $aTest[1] = 'Test|String' $aTest[2] = 'String' _ArrayDisplay($aTest) EndFunc Func _2_If_Problem() Local $vTest If $vTest = '' Then MsgBox(0, '1: $vTest is empty', $vTest) If $vTest == '' Then MsgBox(0, '2: $vTest is empty', $vTest) $vTest = 0 If $vTest = '' Then MsgBox(0, '3: $vTest is empty', $vTest) If $vTest == '' Then MsgBox(0, '4: $vTest is empty', $vTest) $vTest = '' If $vTest = '' Then MsgBox(0, '5: $vTest is empty', $vTest) If $vTest == '' Then MsgBox(0, '6: $vTest is empty', $vTest) EndFunc 1. Why is everything behind the '|'-char cropped? The '|'-char is part of the string, so I don't understand this behavior. Could it be a possible bug or is there a way to escape the vertical line? 'Chr(124)' doesn't work as well. 2. Firstly I used '==' in statements until I noticed, that this method doesn't work with MsgBox(). So I started to use in general only one '=' in my script to not mix them all the time. Today I came across this behavior: If '$vTest' is '0' then 'If $vTest = '' Then ...' evaluates to true. But '$vTest' is zero and not empty. Now I'm forced to mix '==' and '='. And I'm confused. Why does this not work as expected? Why are there two methods at all? Bye Edited April 8, 2009 by dRsrb
bo8ster Posted April 9, 2009 Posted April 9, 2009 dRsrb Some good questions 1. I tried using escape characters like \| and ||. Searching the forum I can only suggest looking here.. I also wondering if anyone else can get it going. I found nothing in the help file not much searching. I did find this. Any suggestions? 2. I have seen this around. I would say, just because AutoIt allows you to be a little lazy, don't be. I would tread == and = like you would in C. Running your program shows me that '==' holds true in all situations. With the first test, I would recommend you initialize that var before you use it like any good programmer. This will stop you having unexpected bugs. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
exodius Posted April 9, 2009 Posted April 9, 2009 (edited) The first situation only happens because of _ArrayDisplay displaying things as a ListView (which uses the "|" to delimit column info). If you do: MsgBox (0, "", $aTest[1]) after you define $aTest[1] then it works just fine. Edited April 9, 2009 by exodius
Ascend4nt Posted April 9, 2009 Posted April 9, 2009 (edited) $vTest = 0 If $vTest = '' Then MsgBox(0, '3: $vTest is empty', $vTest) If $vTest == '' Then MsgBox(0, '4: $vTest is empty', $vTest)Valik recently enlightened me that '==' *forces* a string comparison (and makes it case-sensitive). But the whole bit of '' equals 0 confuses me (unless '' basically means a null pointer, but how it would work in an actual string comparison I wouldn't have a clue).A test for 'If Not $vTest' would make more sense for my code... Edited April 9, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
bo8ster Posted April 9, 2009 Posted April 9, 2009 That would make sense. C/C++ == usually goes for the memory address and you have to use a string compare method to compare strings. Ideally you would get a compile error as you are comparing two different data types, as you say 0 could be seen as null. Generally NULL = 0. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
Ascend4nt Posted April 9, 2009 Posted April 9, 2009 (edited) Actually, in C/C++, == is just a regular 'is equals' operation. [and can't be used to compare strings] '=' in C/C++ on the other hand is an assignment operator. Regarding the == string comparison, I just realized that its pretty much the same as doing: StringCompare($vTest,0) 0 is converted to '0', so null or an empty string won't equal it, which is why this results in True (when $vTest=0): If $vTest == '0' Edited April 9, 2009 by ascendant My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
bo8ster Posted April 9, 2009 Posted April 9, 2009 That's correct. It compares either the pointers or the first element in the array, if forget which, because a string var is a pointer to the start of the array. Now if 0 is converted to a char, that makes things interesting. I would expect "Test = 0 - if Test == 0" to be true every time. That said, in my scripts you will often see int() in use.Either way in summary I recommend using == not = for testing equality.http://en.wikipedia.org/wiki/Equality_(relational_operator) holds some reasons why = is allowed. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
Ascend4nt Posted April 9, 2009 Posted April 9, 2009 The reason = is allowed is totally up to the language interpreter/compiler, it doesn't matter what Wikipedia says. However, it can make debugging easier if you can clearly see where the assignments vs. comparisons are - BUT there's a problem in using '==' in AutoIt, as it incurs a performance hit as Valik pointed out. My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs | Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) | Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code)
bo8ster Posted April 9, 2009 Posted April 9, 2009 Thanks for the link ascendant - I learnt something here. Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]
dRsrb Posted April 9, 2009 Author Posted April 9, 2009 I learnt something here.Me too! Absolutely important tips!Thank you all very much!
andybiochem Posted April 9, 2009 Posted April 9, 2009 Hello! I have two general problems which I don't understand: ....... 1. Why is everything behind the '|'-char cropped? The '|'-char is part of the string, so I don't understand this behavior. Could it be a possible bug or is there a way to escape the vertical line? 'Chr(124)' doesn't work as well. The _ArrayDisplay documentation shows how to get around this: #include <array.au3> _1_Array_Problem() Func _1_Array_Problem() Local $aTest[3] $aTest[0] = 'Test' $aTest[1] = 'Test|String' $aTest[2] = 'String' _ArrayDisplay($aTest,"",-1,0,"¬") EndFunc - Table UDF - create simple data tables - Line Graph UDF GDI+ - quickly create simple line graphs with x and y axes (uses GDI+ with double buffer) - Line Graph UDF - quickly create simple line graphs with x and y axes (uses AI native graphic control) - Barcode Generator Code 128 B C - Create the 1/0 code for barcodes. - WebCam as BarCode Reader - use your webcam to read barcodes - Stereograms!!! - make your own stereograms in AutoIT - Ziggurat Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Box-Muller Gaussian Distribution RNG - generate random numbers based on normal/gaussian distribution - Elastic Radio Buttons - faux-gravity effects in AutoIT (from javascript)- Morse Code Generator - Generate morse code by tapping your spacebar!
dRsrb Posted April 9, 2009 Author Posted April 9, 2009 The _ArrayDisplay documentation shows how to get around this: ...Thank you for the hint. I just edited the "Array.au3" and replaced the vertical line with an other default char.Bye
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