leuce Posted May 17, 2009 Posted May 17, 2009 G'day everyone I have a little script that pastes HTML-like tags into Notepad at the cursor position. The script is as follows: expandcollapse popupGlobal $foo Global $tags Global $len Global $ben Global $numtags Global $j HotKeySet("^{RIGHT}", "NextTag") $foo = '<f1>asdf</f1>asdsdfasdf<s0/><a11></a11>' $j = 0 $tags = StringRegExp ($foo, '(<[/]{0,1}[a-z]{0,3}[0-9]{0,5}[/]{0,1}>)', 3) ; So now $tags[0] is <f1>, $tags[1] is </f1> etc $numtags = UBound($tags) While 1 Sleep(100) WEnd Func NextTag () WinActivate ("Untitled - Notepad", "") WinWaitActive ("Untitled - Notepad", "") ClipPut ($tags[$j]) $len = StringLen ($tags[$j]) Send ("^v") Send("{LEFT " & $len & "}") Send("+{RIGHT " & $len & "}") ; Now if $j is 4 then it should change $j back to 0 ; so that $tags[$j] matches <f1> again If $j = $numtags Then $j = 0 Else $j = $j + 1 EndIf ; ...but it doesn't change $j back to 0 even if $j is 4. ; The question is... why????? EndFunc The user presses Ctrl+right to paste the next tag, but after he gets to the last tag, I want Ctrl+right to go back to the first tag (so it goes in a circle). To do this, $j has to be reset to 0 when the $j count reaches $numtags (in the above case, 4). I want to use $numtags because later I'll make the script read $foo from a file. Yet when I reach the last tag, AutoIt exists with an error telling me that my I've exceeded the number of subscripts in the array, which to my mind means that $j has failed to have been reset to 0. Can anyone point out the obvious? Thanks!
will88 Posted May 17, 2009 Posted May 17, 2009 (edited) the problem is $numtags = UBound($tags) is actually = to 5 not 4("Now if $j is 4 then it should change $j back to 0") HotKeySet("^{RIGHT}", "NextTag") $foo = '<f1>asdf</f1>asdsdfasdf<s0/><a11></a11>' Global $j = 0 $tags = StringRegExp ($foo, '(<[/]{0,1}[a-z]{0,3}[0-9]{0,5}[/]{0,1}>)', 3) $numtags = UBound($tags) MsgBox(0,"",$numtags) While 1 Sleep(100) WEnd Func NextTag () WinActivate ("Untitled - Notepad", "") WinWaitActive ("Untitled - Notepad", "") ClipPut ($tags[$j]) $len = StringLen ($tags[$j]) Send ("^v") Send("{LEFT " & $len & "}") Send("+{RIGHT " & $len & "}") If $j = $numtags-1 Then $j = 0 Else $j += 1 EndIf EndFunc Edited May 17, 2009 by will88 Password-Keeper
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