2dkot Posted December 9, 2008 Share Posted December 9, 2008 Hi, guys So I have function, which must select a peace of string and compare it with another one. And where am I damn wrong? cause I have the following message: Subscript used with non-Array variable.: If $MatchText[0] == $Correct Then If $MatchText^ ERROR Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) Thanks a lot. Link to comment Share on other sites More sharing options...
Andreik Posted December 9, 2008 Share Posted December 9, 2008 Hi, guys So I have function, which must select a peace of string and compare it with another one. And where am I damn wrong? cause I have the following message: Subscript used with non-Array variable.: If $MatchText[0] == $Correct Then If $MatchText^ ERROR Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) Thanks a lot. Check if $MatchText is an array: Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If IsArray($MatchText) Then If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndIf EndFunc If no string found the function returns 0, and this isn't an array. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
2dkot Posted December 10, 2008 Author Share Posted December 10, 2008 Actually, yes. It is not array. But I thought when you use "_StringBetween", it puts selected string to array's "0" element. Link to comment Share on other sites More sharing options...
Andreik Posted December 10, 2008 Share Posted December 10, 2008 (edited) Check the elements of array: #include <Array.au3> If IsArray($MatchText) Then _ArrayDisplay($MatchText) ... EndIf Edited December 10, 2008 by Andreik When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted December 10, 2008 Moderators Share Posted December 10, 2008 Actually, yes. It is not array. But I thought when you use "_StringBetween", it puts selected string to array's "0" element.If it's not an array then the match failed... the proper way to check for an array is like what Andreik showed you "IsArray()"... many functions that return arrays will also allow you to check @error so you can narrow down what specifically the error was. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
2dkot Posted December 10, 2008 Author Share Posted December 10, 2008 If it's not an array then the match failed... the proper way to check for an array is like what Andreik showed you "IsArray()"... many functions that return arrays will also allow you to check @error so you can narrow down what specifically the error was. I found the mistake this is correct: Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText [2] $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) But it doesn't match cause I have "Содержание"&@CRLF as start and @CRLF&"Кол-во листов" as end. But How can I match it and compare if Text, which WinGetText gets, has LF? Link to comment Share on other sites More sharing options...
2dkot Posted December 10, 2008 Author Share Posted December 10, 2008 I found the mistake this is correct: Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText [2] $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) But it doesn't match cause I have "Содержание"&@CRLF as start and @CRLF&"Кол-во листов" as end. But How can I match it and compare if Text, which WinGetText gets, has LF? It works with @LF. My fault. Link to comment Share on other sites More sharing options...
2dkot Posted December 11, 2008 Author Share Posted December 11, 2008 (edited) But now, if I call this func second time it gives the same error. Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText [2] $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) CheckForCorrectForm ($CheckWinTitle, "12"&@CRLF, @CRLF&"Lистов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) Edited December 11, 2008 by 2dkot Link to comment Share on other sites More sharing options...
saywell Posted December 11, 2008 Share Posted December 11, 2008 But now, if I call this func second time it gives the same error.I too have an array produced by StingBetween that does funny things when called more than one.Do arrays have local and global versions like variables?A local variable dies at the end of the function call, and gets reborn anew when it's called again.I wonder if this isn't happening with the array from stringbetween? Is there any way of re-satting the array after the function has run each time?Or is this all nonsense?William Link to comment Share on other sites More sharing options...
2dkot Posted December 12, 2008 Author Share Posted December 12, 2008 (edited) Yeah, it seems that something wrong there. Edited December 12, 2008 by 2dkot Link to comment Share on other sites More sharing options...
2dkot Posted December 12, 2008 Author Share Posted December 12, 2008 If it's not an array then the match failed... the proper way to check for an array is like what Andreik showed you "IsArray()"... many functions that return arrays will also allow you to check @error so you can narrow down what specifically the error was. Sorry for spam, but now, if I call this func second time it gives the same error. Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText [2] $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@CRLF, @CRLF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) CheckForCorrectForm ($CheckWinTitle, "12"&@CRLF, @CRLF&"Lистов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ) Link to comment Share on other sites More sharing options...
Robjong Posted December 12, 2008 Share Posted December 12, 2008 (edited) This has already been anwsered for you. If it's not an array then the match failed... the proper way to check for an array is like what Andreik showed you "IsArray()"... many functions that return arrays will also allow you to check @error so you can narrow down what specifically the error was. just add something like this If Not IsArray($MatchText) Then Return SetError(1, 0, 0) Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch, $Correct, $TestMessage1, $TestMessage2) ; define $MatchText as a local var (not an array) Local $MatchText, $FindText = WinGetText($WinTitle, "") ; if _StringBetween matches $MatchText will be an array $MatchText = _StringBetween($FindText, $StartSearch, $EndSearch) ; check if $MatchText is an array, if not then return 0 and set @error to 1 If Not IsArray($MatchText) Then Return SetError(1, 0, 0) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile, $TestMessage1 & $MatchText[0]) Return SetError(0, 0, 1) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText) FileWriteLine($sFile, $TestMessage2) Return SetError(0, 0, 0) EndIf EndFunc ;==>CheckForCorrectForm Edit: comments Edited December 12, 2008 by Robjong Link to comment Share on other sites More sharing options...
2dkot Posted December 12, 2008 Author Share Posted December 12, 2008 Actually, I 've done it before, and everything was fine with first time of func calling, and nothing shown, even error, in second time. Link to comment Share on other sites More sharing options...
Robjong Posted December 12, 2008 Share Posted December 12, 2008 (edited) Why are you posting that it doesn't work then, or is it something else? Maybe i didn't understand your post, please be more specific. Edited December 12, 2008 by Robjong Link to comment Share on other sites More sharing options...
2dkot Posted December 12, 2008 Author Share Posted December 12, 2008 (edited) I mean that my func works fine only when I do only 1 call Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch , $Correct, $TestMessage1, $TestMessage2) $FindText = WinGetText($WinTitle, "") Dim $MatchText [2] $MatchText = _StringBetween ( $FindText, $StartSearch, $EndSearch) If $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile,$TestMessage2) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText[0] ) FileWriteLine($sFile,$TestMessage1 & $MatchText[0] ) EndIf EndFunc CheckForCorrectForm ($CheckWinTitle, "Содержание"&@LF, @LF&"Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF );- works good CheckForCorrectForm ($CheckWinTitle, "12"&@LF, @LF&"Lистов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF , $time & ": Document test = OK" & @CRLF ); - do nothing even error message, it only says that If $MatchText[0] == $Correct Then If $MatchText^ ERROR Edited December 12, 2008 by 2dkot Link to comment Share on other sites More sharing options...
Robjong Posted December 12, 2008 Share Posted December 12, 2008 is that also the case with this one?http://www.autoitscript.com/forum/index.ph...st&p=616165 Link to comment Share on other sites More sharing options...
Robjong Posted December 12, 2008 Share Posted December 12, 2008 (edited) Hey, I missed some things, maybe provide a working sample of your code next time This one does not have any errors #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Date.au3> #include <String.au3> Global $sFile = @ScriptFullPath & ".txt" Global $time = _Now() Global $CheckWinTitle = "test" CheckForCorrectForm($CheckWinTitle, "??????????" & @CRLF, @CRLF & "???-?? ??????", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF, $time & ": Document test = OK" & @CRLF) CheckForCorrectForm($CheckWinTitle, "12" & @CRLF, @CRLF & "L?????", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = ISSUE" & @CRLF, $time & ": Document test = OK" & @CRLF) Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch, $Correct, $TestMessage1, $TestMessage2) ; define $MatchText as a local var (not an array) Local $MatchText, $FindText = WinGetText(WinGetHandle($WinTitle), "") ; if _StringBetween matches $MatchText will be an array $MatchText = _StringBetween($FindText, $StartSearch, $EndSearch) ; check if $MatchText is an array If IsArray($MatchText) And $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile, $TestMessage1 & $MatchText[0]) Return SetError(0, 0, 1) Else ; here use $MatchText instead of $MatchText[0] because $MatchText is not an array MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText) FileWriteLine($sFile, $TestMessage2 & $MatchText) Return SetError(1, 0, 0) EndIf EndFunc ;==>CheckForCorrectForm Edit: AutoIt3Wrapper Edited December 12, 2008 by Robjong Link to comment Share on other sites More sharing options...
2dkot Posted December 13, 2008 Author Share Posted December 13, 2008 Thanks, u r right. I'll try. Link to comment Share on other sites More sharing options...
2dkot Posted December 15, 2008 Author Share Posted December 15, 2008 Well, it still gives me a 0 in second call ^(((. $MatchText is not an array, but why? Here is a full code: expandcollapse popup$Path = "C:\Documents and Settings\ivanovkv\Рабочий стол\Logs\" $File = "Logfile.txt" $FullPathFile = "C:\Documents and Settings\ivanovkv\Рабочий стол\Logs\Logfile.txt" $time = @hour & "." & @MIN & "." & @SEC $Simpletime = @MDAY & "." & @MON & "." & @YEAR $sFile = $Path & $Simpletime & " - " & $File $CheckWinTitle = WinGetTitle("") CheckForCorrectForm ($CheckWinTitle, "Содержание" & @LF, @LF & "Кол-во листов", "Test 123 Test: test; Test/test? test@test.test, Test", $time & ": Document test = Содержание - Test: ISSUE" & @CRLF , $time & ": Document test = Содержание - Test: OK" & @CRLF ) CheckForCorrectForm ($CheckWinTitle, "Кому(2 из 2)" & @LF, @LF & "Содержание", "Assist", $time & ": Кому(2 из 2) test = - Test: ISSUE" & @CRLF , $time & ": Document test = Кому(2 из 2) - Test: OK" & @CRLF ) Func CheckForCorrectForm($WinTitle, $StartSearch, $EndSearch, $Correct, $TestMessage1, $TestMessage2) If $StartSearch = "Кому(2 из 2)"&@LF Then ControlClick($WinTitle, "", "[CLASS:WindowsForms10.EDIT.app.0.30d38e8; INSTANCE:6]") Sleep (2000) Send("{DOWN}") Sleep (2000) EndIf Local $MatchText, $FindText = WinGetText(WinGetHandle($WinTitle), "") $MatchText = _StringBetween($FindText, $StartSearch, $EndSearch) If IsArray($MatchText) And $MatchText[0] == $Correct Then MsgBox(0, "Active window stats (x,y,width,height):", "Correctly matched" & $MatchText[0]) FileWriteLine($sFile, $TestMessage1 & $MatchText[0]) Return SetError(0, 0, 1) Else MsgBox(0, "Active window stats (x,y,width,height):", "Not Correctly matched" & $MatchText) FileWriteLine($sFile, $TestMessage2 & $MatchText) Return SetError(1, 0, 0) _ArrayDisplay($MatchText) EndIf EndFunc Link to comment Share on other sites More sharing options...
2dkot Posted December 16, 2008 Author Share Posted December 16, 2008 Any advise? 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