Uten Posted April 20, 2009 Posted April 20, 2009 (edited) Why does an array element containing a 0 evaluate to true when compared to a hardcoded string?I would appreciate If someone could take the time to figure out if I have done something wrong before I make a fool out of my self and report a bug.Thanks..My run log in scite.>"F:\portableapps\devtools\scite\..\autoit3tools\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "F:\Documents\code\au3\foo-adrian.au3" /autoit3dir "F:\portableapps\devtools\scite\..\autoit-v3.3.0.0" /UserParams +>20:10:44 Starting AutoIt3Wrapper v.1.10.1.14 Environment(Language:0409 Keyboard:00000414 OS:WIN_2000/Service Pack 4 CPU:X86 ANSI) >Running AU3Check (1.54.14.0) from:F:\portableapps\devtools\scite\..\autoit-v3.3.0.0 +>20:10:47 AU3Check ended.rc:0 >Running:(3.3.0.0):F:\portableapps\devtools\scite\..\autoit-v3.3.0.0\autoit3.exe "F:\Documents\code\au3\foo.au3" (21) : (0)(0) CardType = CardType Evaluates to: True (33) : (0)(0) $i:=2 (21) : (0)(0) 0 = CardType Evaluates to: True (43) : (0)(0) $i:=1 (44) : (0)(0) ERROR: Uhh, no error? $ret:=0 +>20:10:53 AutoIT3.exe ended.rc:0 +>20:10:54 AutoIt3Wrapper Finished >Exit code: 0 Time: 18.646The codeexpandcollapse popup#include-once AutoitSetOption('MustDeclareVars',1) Func dbg($msg, $line=@ScriptLineNumber, $err=@error, $ext=@extended) Local $out = '(' & $line & ') : (' & $err & ')(' & $ext & ') ' & $msg If Not @Compiled AND ProcessExists('SciTE.exe') Then ConsoleWrite( $out & @CRLF) Else DllCall("kernel32.dll", "none", "OutputDebugString", "str", $out) EndIf EndFunc ; Func _ArrayScan(ByRef $arr, $line=@ScriptLineNumber) ; Return quiz type ;text|option|checkbox|mathdrill|mathformula Local $i = 0 If not IsArray($arr) Then Return SetError(1,0,'ERROR') For $i = 1 to $arr[0][0] If $arr[$i][0] = 'CardType' Then dbg($arr[$i][0] & ' = CardType Evaluates to: ' & ($arr[$i][0] = 'CardType')) ExitLoop EndIf Next If $i > $arr[0][0] Then Return SetError(2,0, $i) dbg('$i:=' & $i, $line) Return $arr[$i][1] EndFunc ; Func test__ArrayScan() Local $ret Local $arr[4][2] = [[3,0], ['question', 'Can you ride on a horse?'],['CardType','text'], ['answer', '[yes]|[you can]|[ofcource]']] $ret = _ArrayScan($arr) If Not @error = 0 Then dbg('Uhh, did not expect error?') If Not ($ret = 'text') Then dbg( 'Unexpected return. Expected text got' & $ret) ; Local $arr2a[4][2] = [[3,0],[1,2],[3,4],[5,6]] $ret = _ArrayScan($arr2a) If Not @error = 2 Then dbg('Uhh, no error? $ret:=' & $ret) ; Local $arr2b[4][2] =[[3,0],[0,0],[0,0],[0,0]]; [[3,0],[1,2],[3,4],[5,6]] $ret = _ArrayScan($arr2b) If not @error = 2 Then dbg('ERROR: Uhh, no error? $ret:=' & $ret) ; Local $arr3 = 3 $ret = _ArrayScan($arr3) If Not @error = 1 Then dbg('Uhh, no error? $ret:=' & $ret) EndFunc ; ============================================ test__ArrayScan()EDIT: Added solved in title Edited April 20, 2009 by Uten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Developers Jos Posted April 20, 2009 Developers Posted April 20, 2009 maybe ? : If Not (@error = 2) Then dbg('Uhh, no error? $ret:=' & $ret) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Uten Posted April 20, 2009 Author Posted April 20, 2009 (edited) Good catch.. Unfortunately it does not change anything I get the same runlog if I wrap it up (@error = X). I would think it should make a diffrence, so I'm pussled. Usually I have a error detecting function rather than the check against @error Edit: This is the important line in the run log: (21) : (0)(0) 0 = CardType Evaluates to: True Edited April 20, 2009 by Uten Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
Developers Jos Posted April 20, 2009 Developers Posted April 20, 2009 (edited) Change your test to: If $arr[$i][0] == 'CardType' Then comparing a number with a string will give a true when the number is zero. Jos Edited April 20, 2009 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
Uten Posted April 20, 2009 Author Posted April 20, 2009 Shit, caught by a really bad habit Thanks Jos.. Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling
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