Joris Posted July 12, 2011 Share Posted July 12, 2011 (edited) Hi, This is one of my first AutoIt GUI scripts, followed some tutorials but my GUI goes away as soon as it's shown. I know the code is far from optimal but I haven't written code for a long time... Code is below, all help appreciated! expandcollapse popup#include <file.au3> #include <guiconstants.au3> $linecount = _FileCountLines( "c:\repeater.log" ) $file1 = FileOpen("c:\repeater.log", 0) $match = "Server added to list " $currentline = $linecount Global $client[10] Global $Button[11] $found = 0 $clientid = "" $run = 1 While $run = 1 $line = String(FileReadLine($file1,$currentline)) If StringInStr($line, $match) = 1 Then $found = $found + 1 $client[$found] = StringTrimLeft($line, 21) EndIf $currentline = $currentline - 1 If $found = 10 Then $run = 0 If $currentline = 0 Then $run = 0 WEnd $show = 1 $guiheight = (2 + ($found * 20) + (($found - 1) * 2)) GuiCreate("Sessions", 54, $guiheight) While not(($show - 1) = $found) $buttonheight = (2 + (($show - 1) * 22)) $Button[$show] = GuiCtrlCreateButton($client[$show], 2, $buttonheight, 50, 20) $show = $show + 1 WEnd GuiSetState() $guimsg = GuiGetMsg() While $guimsg <> $GUI_EVENT_CLOSE $guimsg = GuiGetMsg() Select Case $guimsg = $Button[1] GuiDelete() $clientid = $client[1] ExitLoop Case $guimsg = $Button[2] GuiDelete() $clientid = $client[2] ExitLoop Case $guimsg = $Button[3] GuiDelete() $clientid = $client[3] ExitLoop Case $guimsg = $Button[4] GuiDelete() $clientid = $client[4] ExitLoop Case $guimsg = $Button[5] GuiDelete() $clientid = $client[5] ExitLoop Case $guimsg = $Button[6] GuiDelete() $clientid = $client[6] ExitLoop Case $guimsg = $Button[7] GuiDelete() $clientid = $client[7] ExitLoop Case $guimsg = $Button[8] GuiDelete() $clientid = $client[8] ExitLoop Case $guimsg = $Button[9] GuiDelete() $clientid = $client[9] ExitLoop Case $guimsg = $Button[10] GuiDelete() $clientid = $client[10] ExitLoop EndSelect WEnd Run("ChunkViewer.exe") WinWaitActive("ChunkVNC Viewer") Send($clientid & "{ENTER}") WinWaitActive("VNC Authentication") Send("password{ENTER}") Edited July 12, 2011 by Joris Link to comment Share on other sites More sharing options...
martin Posted July 12, 2011 Share Posted July 12, 2011 Hi, This is one of my first AutoIt GUI scripts, followed some tutorials but my GUI goes away as soon as it's shown. I know the code is far from optimal but I haven't written code for a long time... Code is below, all help appreciated! expandcollapse popup#include <file.au3> #include <guiconstants.au3> $linecount = _FileCountLines( "c:\repeater.log" ) $file1 = FileOpen("c:\repeater.log", 0) $match = "Server added to list " $currentline = $linecount Global $client[10] Global $Button[11] $found = 0 $clientid = "" $run = 1 While $run = 1 $line = String(FileReadLine($file1,$currentline)) If StringInStr($line, $match) = 1 Then $found = $found + 1 $client[$found] = StringTrimLeft($line, 21) EndIf $currentline = $currentline - 1 If $found = 10 Then $run = 0 If $currentline = 0 Then $run = 0 WEnd $show = 1 $guiheight = (2 + ($found * 20) + (($found - 1) * 2)) GuiCreate("Sessions", 54, $guiheight) While not(($show - 1) = $found) $buttonheight = (2 + (($show - 1) * 22)) $Button[$show] = GuiCtrlCreateButton($client[$show], 2, $buttonheight, 50, 20) $show = $show + 1 WEnd GuiSetState() $guimsg = GuiGetMsg() While $guimsg <> $GUI_EVENT_CLOSE $guimsg = GuiGetMsg() Select Case $guimsg = $Button[1] GuiDelete() $clientid = $client[1] ExitLoop Case $guimsg = $Button[2] GuiDelete() $clientid = $client[2] ExitLoop Case $guimsg = $Button[3] GuiDelete() $clientid = $client[3] ExitLoop Case $guimsg = $Button[4] GuiDelete() $clientid = $client[4] ExitLoop Case $guimsg = $Button[5] GuiDelete() $clientid = $client[5] ExitLoop Case $guimsg = $Button[6] GuiDelete() $clientid = $client[6] ExitLoop Case $guimsg = $Button[7] GuiDelete() $clientid = $client[7] ExitLoop Case $guimsg = $Button[8] GuiDelete() $clientid = $client[8] ExitLoop Case $guimsg = $Button[9] GuiDelete() $clientid = $client[9] ExitLoop Case $guimsg = $Button[10] GuiDelete() $clientid = $client[10] ExitLoop EndSelect WEnd Run("ChunkViewer.exe") WinWaitActive("ChunkVNC Viewer") Send($clientid & "{ENTER}") WinWaitActive("VNC Authentication") Send("password{ENTER}") You have used select and references to controls which don't exist. The controls which don't exist had an id of 0, and if there is no msg to handle $guimsg is 0 so the first case where a control id is zsero is executed. One way to fix it is to add a case to defend against this- Select case $guimsg = 0;make this the first case so nothing is done if $guimsg is zero case some other case Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Joris Posted July 12, 2011 Author Share Posted July 12, 2011 That works! Thanks a lot! But I don't really understand why that works? If the select comes up empty why doesn't it just loop back inside the 'while'? Since there still is no $GUI_EVENT_CLOSE... Link to comment Share on other sites More sharing options...
martin Posted July 12, 2011 Share Posted July 12, 2011 That works! Thanks a lot! But I don't really understand why that works? If the select comes up empty why doesn't it just loop back inside the 'while'? Since there still is no $GUI_EVENT_CLOSE... I explained why in my reply. If there is no message then say it gets to this case Case $guimsg = $Button[7] GuiDelete() $clientid = $client[7] ExitLoop $guimsg is 0 because there is no message, $Button[7] is zero (or in fact '' which equates to zero) because you haven't created the it, so the script continues with GuiDelete and on to ExitLoop. Maybe it's button 9 or 10 but without your repeater.log file we can't tell. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. Link to comment Share on other sites More sharing options...
Joris Posted July 13, 2011 Author Share Posted July 13, 2011 Thanks for the crystal clear reply! If you don't mind, I have a little follow-up question since I'm new to programming in AutoIT. This means that in AutoIt from the moment a variable gets declared it is eqaul to 0 (zero), not NULL? Link to comment Share on other sites More sharing options...
martin Posted July 13, 2011 Share Posted July 13, 2011 Thanks for the crystal clear reply!If you don't mind, I have a little follow-up question since I'm new to programming in AutoIT.This means that in AutoIt from the moment a variable gets declared it is eqaul to 0 (zero), not NULL?All variable in AutoIt are variants so the type is often translated to the appropriate type by the context or usage. In fact when declared I think all variable are any empty string rather than being 0 so I suppose that is close to being NULL.You can find this out for yourself btw, have a look in the help for VarGetType. Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script. 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