EdDyreen Posted March 22, 2012 Share Posted March 22, 2012 (edited) 'Using autoIT v3.3.8.1Next code pops up 2 MsgBoxes, $state=1.However the 2nd time using a call ( function, array ) command.$array is build with a regular expression.The 2nd time however the Number command fails to evaluate,and MsgBox incorrectly displays $state=0.Just run the code below and see for yourself.Is it a bug, or did I miss the obvious ?Global $arg = True callOK_ ( 'func_', $arg ) callWrong_ ( 'func_', $arg ) Exit Func callOK_ ( $func, $callArgs = '' ) ; ( Local $array[2] $array[0] = 'CallArgArray' $array[1] = $arg _ArrayDisplay ( $array ) $return = Call ( $func, $array ) ; ) EndFunc Func callWrong_ ( $func, $callArgs = '' ) ; ( $array = StringRegExp ( $callArgs, '((?<=s"|^")[^"]*(?=")|[^s",]+)', 3 ) _ArrayInsert ( $array, 0, 'CallArgArray' ) _ArrayDisplay ( $array ) $return = Call ( $func, $array ) ; ) EndFunc Func func_ ( $state = True ) ; ( $state = Number ( $state ) MsgBox ( 0, '', '$state=' &$state &'_' ) ; ) EndFunc Edited March 22, 2012 by EdDyreen • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
EdDyreen Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) 'Not sure why but somehow the values type is changed to string.Next solution isn't very elegant, but it works.Func callWrong_ ( $func, $callArgs = '' ) ; ( $array = StringRegExp ( $callArgs, '((?<=s"|^")[^"]*(?=")|[^s",]+)', 3 ) _ArrayInsert ( $array, 0, 'CallArgArray' ) ;_ArrayDisplay ( $array ) For $i = 1 To UBound ( $array ) - 1 Step 1 ; Select ; Case $array[$i] == 'True' ; $array[$i] = True ; Case $array[$i] == 'False' ; $array[$i] = False ; EndSelect ; Next $return = Call ( $func, $array ) ; ) EndFunc Edited March 22, 2012 by EdDyreen • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
jchd Posted March 22, 2012 Share Posted March 22, 2012 You beat me on it! To see why, run: expandcollapse popup#include <Array.au3> Global $arg = True callOK_ ( 'func_', $arg ) callWrong_ ( 'func_', $arg ) Exit Func callOK_ ( $func, $callArgs = '' ) ; ( Local $array[2] $array[0] = 'CallArgArray' $array[1] = $arg _ArrayDisplay ( $array ) ConsoleWrite(_VarDump($array) & @LF & @LF) $return = Call ( $func, $array ) ; ) EndFunc Func callWrong_ ( $func, $callArgs = '' ) ; ( Local $array = StringRegExp ( $callArgs, '((?<=s"|^")[^"]*(?=")|[^s",]+)', 3 ) _ArrayInsert ( $array, 0, 'CallArgArray' ) _ArrayDisplay ( $array ) ConsoleWrite(_VarDump($array) & @LF) $return = Call ( $func, $array ) ; ) EndFunc Func func_ ( $state = True ) ; ( $state = Number ( $state ) MsgBox ( 0, '', '$state=' &$state &'_' ) ; ) EndFunc Func _VarDump(ByRef $vVar, $sIndent = '') Select Case IsDllStruct($vVar) Return 'Struct(' & DllStructGetSize($vVar) & ') @:' & Hex(DllStructGetPtr($vVar)) & ' = ' & __ShortHexDump(DllStructGetPtr($vVar, 1), DllStructGetSize($vVar)) Case IsArray($vVar) Local $iSubscripts = UBound($vVar, 0) Local $sDims = 'Array' $iSubscripts -= 1 For $i = 0 To $iSubscripts $sDims &= '[' & UBound($vVar, $i + 1) & ']' Next Return $sDims & @CRLF & _VarDumpArray($vVar, $sIndent) Case IsBinary($vVar) Return 'Binary(' & BinaryLen($vVar) & ') = ' & __ShortHexDump(DllStructGetPtr($vVar, 1), DllStructGetSize($vVar)) Case IsBool($vVar) Return 'Boolean(' & $vVar & ')' Case IsFloat($vVar) Return 'Float(' & $vVar & ')' Case IsHWnd($vVar) Return 'HWnd(' & $vVar & ')' Case IsInt($vVar) Return 'Integer(' & $vVar & ')' Case IsKeyword($vVar) Return 'Keyword(' & $vVar & ')' Case IsPtr($vVar) Return 'Pointer(' & $vVar & ')' Case IsObj($vVar) Return 'Object(' & ObjName($vVar) & ')' Case IsString($vVar) Return 'String(' & StringLen($vVar) & ") '" & $vVar & "'" Case Else Return 'Unknown(' & $vVar & ')' EndSelect EndFunc Func _VarDumpArray(ByRef $aArray, $sIndent = '') Local $sDump Local $sArrayFetch, $sArrayRead, $bDone Local $iSubscripts = UBound($aArray, 0) Local $aUBounds[$iSubscripts] Local $aCounts[$iSubscripts] $iSubscripts -= 1 For $i = 0 To $iSubscripts $aUBounds[$i] = UBound($aArray, $i + 1) - 1 $aCounts[$i] = 0 Next $sIndent &= @TAB While 1 $bDone = True $sArrayFetch = '' For $i = 0 To $iSubscripts $sArrayFetch &= '[' & $aCounts[$i] & ']' If $aCounts[$i] < $aUBounds[$i] Then $bDone = False Next $sArrayRead = Execute('$aArray' & $sArrayFetch) If @error Then ExitLoop Else $sDump &= $sIndent & $sArrayFetch & ' => ' & _VarDump($sArrayRead, $sIndent) If Not $bDone Then $sDump &= @CRLF Else Return $sDump EndIf EndIf For $i = $iSubscripts To 0 Step -1 $aCounts[$i] += 1 If $aCounts[$i] > $aUBounds[$i] Then $aCounts[$i] = 0 Else ExitLoop EndIf Next WEnd EndFunc Func __ShortHexDump($ptr, $blen) Local $tmpbin = DllStructCreate("byte[" & $blen & "]", $ptr) If $blen <= 64 Then Return('0x' & Hex(DllStructGetData($tmpbin, 1))) Else Return('0x' & Hex(BinaryMid(DllStructGetData($tmpbin, 1), 1, 32)) & ' ... ' & Hex(BinaryMid(DllStructGetData($tmpbin, 1), $blen - 31, 32))) EndIf EndFunc Hint: StringRegExp doesn't return a boolean with value True, but a string containing 'True' which is 0 under Number(). 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...
EdDyreen Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) 'Thanks for the _VarDump functions jchd, can't find them in the UDF section, I find them usefull. Edited March 22, 2012 by EdDyreen • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
jchd Posted March 22, 2012 Share Posted March 22, 2012 Very useful at times indeed! BTW, just insert: $array[0] = ($array[0] = True) right after the regexp (and its error checking) is good enough. 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...
EdDyreen Posted March 22, 2012 Author Share Posted March 22, 2012 Very useful at times indeed! BTW, just insert: $array[0] = ($array[0] = True) right after the regexp (and its error checking) is good enough. ' Sorry, don't understand, could you elaborate ? Where do I insert this code ? • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
jchd Posted March 22, 2012 Share Posted March 22, 2012 Func callWrong_ ( $func, $callArgs = '' ) ; ( Local $array = StringRegExp ( $callArgs, '((?<=s"|^")[^"]*(?=")|[^s",]+)', 3 ) $array[0] = ($array[0] = True) <<===== here _ArrayInsert ( $array, 0, 'CallArgArray' ) _ArrayDisplay ( $array ) ConsoleWrite(_VarDump($array) & @LF) $return = Call ( $func, $array ) ; ) EndFunc 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...
EdDyreen Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) How does that works without using an if statement, where can I find more info on that ? Global $array[4] $array[0] = 'True' $array[1] = 'False' $array[2] = 'string, no replace' $array[3] = '' $array[0] = ($array[0] = True) $array[1] = ($array[1] = True) $array[2] = ($array[2] = True) $array[3] = ($array[3] = True) ConsoleWrite( _VarDump ( $array ) &@CRLF ) Array[4] [0] => Boolean(True) [1] => Boolean(True) [2] => Boolean(True) [3] => Boolean(False) Sadly, it seems to not respect non-boolean values. Edited March 22, 2012 by EdDyreen • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
jchd Posted March 22, 2012 Share Posted March 22, 2012 Oops, I read your fix too fast and interpreted you needed a boolean issue in all cases for the first actual parameter in the array. My bad.While being incorrect for your use, it works very simple: ($array[0] = True) is an assertion, just like a condition in an If statement, which is boolean by nature, so either True or False and then assigned to the value (which happens to be the same location).. 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...
EdDyreen Posted March 22, 2012 Author Share Posted March 22, 2012 (edited) 'So it's actually the brackets () that make it an assertion,I wish someone added those things to the au3 help file, somewhere.Je comprend maintenant jchd, merçi beacoup. ( Je sera en ardeche dans pas longtemps aussi, profiter du soleil. ) Edited March 22, 2012 by EdDyreen • Any number images • Images of any size • Any number of URLs • Any number of lines Link to comment Share on other sites More sharing options...
jchd Posted March 22, 2012 Share Posted March 22, 2012 Cool, maybe even a bit warm if you wait too long!Enjoy your stay at any rate!et bravo pour ton français 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...
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