DarkShadow6 Posted June 8, 2009 Share Posted June 8, 2009 My first post. Yay. Well, I've been teachig myself AutoIt script for about a week, and I've already created my own version of Mr. Llama's command line on The Edge of Nowhere forums. And... Well... I've run into a problem. Mr Llama's code always exited when it encountered the command "Trans" without a window title or transparancy argument (Trans WINDOWNAME 255). So, I tried to use the following but with no progress: CODE $Input = StringSplit($InputAll, "/") ... If $Input[1] = "-quit" Then Exit ElseIf $Input[1] = "-help" Then ... ElseIf $Input[1] = "-opacity" and IsDeclared("input[2]") and IsDeclared("input[3]") Then ... Etcetera etcetera. Any help on trying to find if an array's child exists? Also, I did try searching. No luck. Also also, another way I tought of doing it would be to set variables ($Input1, $Input2, etc) for every value in the array. But I want it to get every word, not just the first three (although that's what I'm using). Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 8, 2009 Share Posted June 8, 2009 Welcome to the forum! If I get you right you want to check if there is exactly 3 items in the array? Then use UBound= ElseIf $Input[1] = "-opacity" and UBound($Input) = 3 Then .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
DarkShadow6 Posted June 8, 2009 Author Share Posted June 8, 2009 (edited) See my post... "But I want it to get every word, not just the first three (although that's what I'm using). " So, no, I don't want to make sure there is exactily three. Help has no arguments, and echo has two. Really all I needed was a way to check if a value existed in an array. Thanks so much, ill try that out! Edit: Well that was short lived. It didnt work. Here's some output: GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & $Input[2] & @CRLF & "-> ") GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & ^ ERROR I thought it worked. But maybe its just the echo... Heres the full code: CODE #NoTrayIcon #include <GUIConstants.au3> #include <EditConstants.au3> #include <WindowsConstants.au3> HotKeySet("{ENTER}", "Enter") Global $MainForm = GUICreate("DarkCom", 500, 500) Global $StartText = "DarkCom 2.0 command line function executer" & @CRLF & "Type '-help' to get started" & @CRLF & "Version 2.1" & @CRLF & "-> " Global $InputAll = "" Global $Input = "" Global $EditOutput = GuiCtrlCreateEdit($StartText, 0, 0, 500, 480, $ES_READONLY + $ES_AUTOVSCROLL + $ES_AUTOHSCROLL + $WS_HSCROLL + $WS_VSCROLL + $WS_OVERLAPPED) Global $EditInput = GuiCtrlCreateInput("-", 0, 480, 500, 20) GUISetState(@SW_SHOW) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop EndIf WEnd Func Enter() If WinActive($MainForm) Then $InputAll = GUICtrlRead($EditInput) GuiCtrlSetData($EditInput, "-") $Input = StringSplit($InputAll, "/") If $Input[1] = "-quit" Then Exit ElseIf $Input[1] = "-help" Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "You cannot use '/' except to separate commands." & @CRLF & _ "Possible commands are as follows:" & @CRLF & _ "-quit: Quits the command line." & @CRLF & _ "-help: Shows this help message." & @CRLF & _ "-opacity/[window title]/[0 - 255]: Set the opacity (transparency) of a window." & @CRLF & _ "-speak/[sentance]: Commands your default TTY text reader to read [sentance]." & @CRLF & _ "-hide/[window title]: Hide the specified window. For saftey purposes you can't hide this window." & @CRLF & _ "-show/[window title]: Show the specified window." & @CRLF & _ "-title/[window title]/[new title]: Replace the window's title." & @CRLF & _ "-echo/[message]: Echo [message]." & @CRLF & _ "-clear: Clear this output box." & @CRLF & _ "-> ") ElseIf $Input[1] = "-opacity" and UBound($Input) == 3 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "The transparency value of '" & $Input[2] & "' is being added to the window named '"& $Input[3] & "'..." & @CRLF & _ "-> ") WinSetTrans($Input[2], "", $Input[3]) ElseIf $Input[1] = "-speak" and UBound($Input) == 2 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "Speaking '" & $Input[2] & "', please wait..." & @CRLF & _ "-> ") $TempFile = @TempDir & '\SpeakFile.vbs' FileWriteLine($TempFile, 'Dim Talk' & @CRLF & _ @CRLF & 'Set Talk = WScript.CreateObject("SAPI.SpVoice")' & @CRLF & _ @CRLF & 'Talk.Speak "' & $Input[2] & '"') RunWait('Wscript.exe SpeakFile.vbs', @TempDir) FileDelete($TempFile) ElseIf $Input[1] = "-hide" and UBound($Input) == 2 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "Hiding window '" & $Input[2] & "'..." & @CRLF & _ "-> ") WinSetState($Input[2], "", @SW_HIDE) ElseIf $Input[1] = "-show" and UBound($Input) == 2 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "Showing window '" & $Input[2] & "'..." & @CRLF & _ "-> ") WinSetState($Input[2], "", @SW_SHOW) ElseIf $Input[1] = "-title" and UBound($Input) == 3 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "Setting window title '" & $Input[2] & "' to '"& $Input[3] & "'..." & @CRLF & _ "-> ") WinSetTitle($Input[2], "", $Input[3]) ElseIf $Input[1] = "-echo" and UBound($Input) == 2 Then GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & $Input[2] & @CRLF & _ "-> ") ElseIf $Input[1] = "-clear" Then GuiCtrlSetData($EditOutput, $StartText) Else GuiCtrlSetData($EditOutput, GUICtrlRead($EditOutput) & "Error: the command name entered does not exist or you didn't provide the required arguments for it." & @CRLF & _ "-> ") EndIf Else HotKeySet("{ENTER}") Send("{ENTER}") HotKeySet("{ENTER}", "Enter") EndIf EndFunc I am stumped why it doesn't seem to work. Nothing works. I tried IfDeclared, that wasnt right. I try UBound but it says Input[2] doesnt exist if it rreally does. ?!?!?!?!?!?!?!? Edited June 8, 2009 by DarkShadow6 Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 8, 2009 Share Posted June 8, 2009 (edited) Are you trying to say UBound wont work or what? I don't get the problem, maybe if you post a reproducer (it should be short and working/runnable). Edit: Oh I see you edited your post, I am glad you found a solution. Edited June 8, 2009 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
DarkShadow6 Posted June 8, 2009 Author Share Posted June 8, 2009 (edited) I gess im confuzed... Oh great Anyway theres the source I just want it to perform the reqired action if one: the array has # many children (1 for echo, 0 for help etc) If you actually typed it if it meets those requrements then it does it... Well sort of It glitched and gave me the error output in the outputbox. When I did -echo/HELLO it did it. But when I do -echo alone, it gives me an error and quits. I hope im making sense. I sure dont feel like I am. ALSO EDIT: I forgot, but all the commands that don;t use UBound are fine. like clear and help. those are OK. its Echo, hide, show etc that break. Just run it to see for urself all the bugs that the multi-arguments commands produce. I cant find the problem, and my young 13 year old mind is already fried from running on no sleep for the past 3 days, doing schoolwork and this darned script. Edited June 8, 2009 by DarkShadow6 Link to comment Share on other sites More sharing options...
DarkShadow6 Posted June 8, 2009 Author Share Posted June 8, 2009 OMFG I FIXED IT The UBound worked... I just needed to add an extra one to it to work... Like this: ElseIf $Input[1] = "-echo" and UBound($Input) == 2 Then to ElseIf $Input[1] = "-echo" and UBound($Input) == 3 Then worked. I dont know why. But it did. Now to add some more commands and release it! Thanks for all the help AdmiralAlkex! Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 8, 2009 Share Posted June 8, 2009 (edited) UBound returns the amount of elements, but arrays start at 0. $Array[3] would return UBound($Array) = 4. Get it? Otherwise I recommend you check Arrays on our wiki, it is quite good explained there. Edited June 8, 2009 by AdmiralAlkex .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
DarkShadow6 Posted June 9, 2009 Author Share Posted June 9, 2009 makes sense thx Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted June 9, 2009 Share Posted June 9, 2009 makes sense thxNP .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface 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