100 likes | 224 Views
Arrays and String Manipulation. Week 6. Arrays. $ arr [3] ; Make room for three elements ;Assign some data. Array starts from 0 position $ arr [0]="Element 1" $ arr [1]="Element 2" $ arr [2]="Element 3“ Msgbox (0,"", $ arr [2]). Another way to Declare Arrays.
E N D
Arrays $arr[3] ; Make room for three elements ;Assign some data. Array starts from 0 position $arr[0]="Element 1" $arr[1]="Element 2" $arr[2]="Element 3“ Msgbox(0,"", $arr[2])
Another way to Declare Arrays $arr[3] = ["element 1", "element 2", "element 3"] Msgbox(0,"", $arr[2])
String Manipulation • Very practical, but a bit boring • Lots of String Manipulation Functions • StringInStr, StringLen, StringLower, StringMid, StringRight, StringTrimLeft, StringTrimRight, StringUpper, StringCompare, StringReplace, StringSplit
Skeleton Code – Excel Control #include "U:\MURT 102\install\Include\Excel.au3" ; If you have the full installation of AutoIt, you don't need to give the pathname, but can just provide Excela.u3 ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{F1}", "Start") While 1 Sleep(100) Wend Func Start() $oExcel = RunExcel() for $r = 1 to 10 $myString = _ExcelReadCell($oExcel, $r,1) ;Value read from cell ;Your Code Goes Here _ExcelWriteCell($oExcel, $myString, $r,$c) next EndFunc ;==>Start Func Quit() Exit EndFunc ;==>Quit FuncRunExcel() Local $arr[10] = ["element 1", "element 2", "element 3", "element 4", "element 5", "element 6", "element 7", "element 8", "element 9", "10th element"] $oExcel = _ExcelBookNew() $c = 1 for $r = 1 to 10 _ExcelWriteCell($oExcel, $arr[$r-1], $r,$c) next return $oExcel EndFunc
Grab the Numbers on the Right • Grab the numbers of the right with StringRight • Check if the value is a number with StringIsDigit • Past the number into the adjacent column with _ExcelWriteCell($oExcel, $myString,$r,2) • Make this now work using StringTrimRight • Remove the n-number of characters with StringLen()
String in Strings • Find the string “1” with StringInStr • If you find it, put in the column “I found it” • Replace with word “element” with “M&M” using StringReplace
String Compare • Let’s modify our Google/Notepad program to look at any combination of LowerCase or UpperCase versions of “FireFox” or “notepad” using StringCompare • Skeleton Code on Next Page
Skeleton Code ;All future code should include this template http://cl1p.net/123456789 HotKeySet("{ESC}", "Quit") HotKeySet("{SPACE}", "Start") HotKeySet("{F1}","CloseWindow") While 1 Sleep(100) Wend Func Start() $val = inputbox("","Type in your Program") If $val == "notepad" Then run("notepad.exe") WinWaitActive("[Class:Notepad]") Send("Hello") ElseIf $val == "firefox" Then run("C:\Program Files\Mozilla Firefox\firefox.exe") WinWaitActive("[Class:MozillaUIWindowClass]") ControlClick("[Class:MozillaUIWindowClass]","","[CLASS:MozillaWindowClass; INSTANCE:1]","left",1,384, 35) sleep(10) ControlSend("[CLASS:MozillaUIWindowClass]", "","[CLASS:MozillaWindowClass; INSTANCE:1]" , "http://www.google.com{ENTER}") WinWaitActive("Google") Else Traytip("Wrong Input", $val, 10) Start() EndIf EndFunc Func Quit() Exit EndFunc FuncCloseWindow() If WinActive("[Class:Notepad]") Then WinClose("[Class:Notepad]") ElseIfWinActive("[Class:MozillaUIWindowClass]") Then WinClose("[Class:MozillaUIWindowClass]") EndIf EndFunc
Let’s Talk about Projects We’ve lost Fridays You have Spring Break You guys are already skilled