Jump to content

GUI flashes on screen and then disappears


chandler8
 Share

Recommended Posts

Hey Everyone.. I have been working on this project for a few days and now have added the code to a GUI. The problem I have is when the script is run, the GUI flashes really fast on the screen and you can't do anything with it. I have tried to add a Sleep(10) in the code and this helps to keep the GUI visable, but when you hit the start button nothing happens. The GUI is designed with three buttons that run the same script, but to different Control ID's on an external program. If I comment out the functions and then run the script it works fine, however when am calling the function this is where all the problems start. Any ideas??? In addition, is there anyway that you can stop the script when it's running and then start it again and begin where you left off?


#include <Array.au3>
#include <GUIConstants.au3>

Func _FileReadToArray($sFilePath, ByRef $aArray)
    Local $hFile
    $hFile = FileOpen($sFilePath, 0)
    If $hFile = -1 Then
        SetError(1)
        Return 0
    EndIf
    $aArray = StringSplit(StringStripCR( FileRead($hFile, FileGetSize($sFilePath))), @LF)
    FileClose($hFile)
    Return 1
EndFunc;==>_FileReadToArray

Local $filePath = @DesktopDir &'\Stocks.txt'
Local $aArray = ''
_FileReadToArray($filePath, $aArray)
Local $sArray = _SeperateEachWord($aArray); should have each 'word' now in an array

Func _SeperateEachWord(ByRef $aArray, $dDelimeter = ' ')
    For $i = 1 To Ubound($aArray) - 1
        If $aArray[$i] <> '' Then 
            $SplitSpace = StringSplit($aArray[$i], $dDelimeter)
            For $x = 1 To UBound($SplitSpace) - 1
                $sArray = $sArray & $SplitSpace[$x] & Chr(01)
    
          Next
        EndIf
    Next
    Return StringSplit(StringTrimRight($sArray, 1), Chr(01))
EndFunc


GUICreate("Millenium Script")
$buttonstart1 = GUICtrlCreateButton ("Start Script 1",50,100,100,25)
GUICtrlSetOnEvent(-1, "buttonstart1")
$buttonstart2 = GUICtrlCreateButton("Start Script 2",50,150,100,25)
GUICtrlSetOnEvent(-1, "buttonstart2")
$buttonstart3 = GUICtrlCreateButton("Start Script 3",50,200,100,25)
GUICtrlSetOnEvent(-1, "buttonstart3")
$buttonstop = GUICtrlCreateButton("Stop", 150,150,70,22)
GUISetState()


Func buttonstart1()
    While 1
        $msg = GUIGetMsg()
        If $msg = $buttonstart1 Then
            $count = 1                  ; Set the counter
            Do                          ; Execute the loop "until" the counter is greater than 20
                For $x = 1 To UBound($sArray) - 1   ;go through the array and execute with focus on the control ID
                    ControlSend("Form1","", 1836126, $sArray[$x])
                    ;Sleep(1000)
                    ControlSend("Form1", "", 1836126, "{Enter}")
                    Sleep(1000)
                    ControlSend("Form1","", 1836126, "{BackSpace 20}")
                Next
                    $count = $count + 1     ; Increase the count by one
            Until $count > 5
                    MsgBox(0, "Click start to Continue ", "Search finished!")   ; Finished
        EndIf
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
EndFunc

Func buttonstart2()
    While 1
        $msg = GUIGetMsg()
        If $msg = $buttonstart2 Then
            $count = 1                  ; Set the counter
            Do                          ; Execute the loop "until" the counter is greater than 20
                For $x = 1 To UBound($sArray) - 1   ;go through the array and execute with focus on the control ID
                    ControlSend("Form1","", 1049864, $sArray[$x])
                    Sleep(1000)
                    ControlSend("Form1", "", 1049864, "{Enter}")
                    Sleep(1000)
                    ControlSend("Form1","", 1049864, "{BackSpace 20}")
                Next
                    $count = $count + 1     ; Increase the count by one
            Until $count > 5
                    MsgBox(0, "Click start to Continue ", "Search finished!")   ; Finished
        EndIf
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
EndFunc

Func buttonstart3()
    While 1
        $msg = GUIGetMsg()
        If $msg = $buttonstart1 Then
            $count = 1                  ; Set the counter
            Do                          ; Execute the loop "until" the counter is greater than 20
                For $x = 1 To UBound($sArray) - 1   ;go through the array and execute with focus on the control ID
                    ControlSend("Form1","", 1312058, $sArray[$x])
                    Sleep(1000)
                    ControlSend("Form1", "", 1312058, "{Enter}")
                    Sleep(1000)
                    ControlSend("Form1","", 1312058, "{BackSpace 20}")
                Next
                    $count = $count + 1     ; Increase the count by one
            Until $count > 5
                    MsgBox(0, "Click start to Continue ", "Search finished!")   ; Finished
        EndIf
        If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    Wend
EndFunc

[\Code]


            
        

        

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    

    
        
            
                


    
        
    

                
                
                    
                        

                    
                
            
        
        
            
                


greenmachine
            
            
                Posted 
                
            
        
    
    
        


greenmachine
            
        
        
            
                
                    


    
        
    

                    
                    
                        

                    
                
            
            
                Active Members
                
            
            
                
                    
                        
                            
                                
                            
                                 1.2k
                            
                                
                            
                        
                        
                    
                
            
            
                

            
        
    
    
        



    
        
            
                
                    
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            Well, at first glance I notice that you have 3 functions with while loops inside of them (they'll definitely keep it open), but you have none outside the functions.  This means that since functions aren't called on their own, your script is running right over them and exiting.  What you need is a while loop getting gui messages at the end of (or before...) the functions.  This way, you'll be able to access your GUI.

As for the pause thingy, use a hotkey.  This is the example of HotKeySet from the helpfile:
; Press Esc to terminate script, Pause/Break to "pause"

Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
HotKeySet("+!d", "ShowMessage") ;Shift-Alt-d

;;;; Body of program would go here;;;;
While 1
    Sleep(100)
WEnd
;;;;;;;;

Func TogglePause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
        ToolTip('Script is "Paused"',0,0)
    WEnd
    ToolTip("")
EndFunc

Func Terminate()
    Exit 0
EndFunc

Func ShowMessage()
    MsgBox(4096,"","This is a message.")
EndFunc
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...