Sign in to follow this  
Followers 0
Skrip

Stop button not working?

4 posts in this topic

#1 ·  Posted (edited)

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>
Global $msgbo
$stop = 0
$moveon = 0
$i = 0
$random1 = 0
$pause = 0
$Form1 = GUICreate("********", 574, 211, 193, 115)
$Input1 = GUICtrlCreateInput("Type file address or click browse...", 112, 32, 433, 21)
$Button1 = GUICtrlCreateButton("Browse", 24, 16, 81, 25, 0)
$Button2 = GUICtrlCreateButton("Start", 24, 48, 81, 25, 0)
$Label1 = GUICtrlCreateLabel("Number of Lines to ******:", 120, 56, 133, 17)
$Input2 = GUICtrlCreateInput("1000", 256, 56, 57, 17)
$Group1 = GUICtrlCreateGroup("*********", 184, 112, 177, 97)
$Label2 = GUICtrlCreateLabel("Completed:", 200, 136, 160, 17)
$Label3 = GUICtrlCreateLabel("Line: ", 200, 160, 160, 17)
$Label4 = GUICtrlCreateLabel("Wrote: ", 200, 184, 160, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button3 = GUICtrlCreateButton("Stop *********", 376, 168, 91, 25, 0)
ControlDisable("*********", "", $Button3)
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $file_browse = FileOpenDialog("Select a File", "", "All(*.*)", 1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Please select a different file, or restart the program.")
            Else
                GUICtrlSetData($Input1, $file_browse)
            EndIf
        Case $Button2
            ControlDisable("********", "", $Button1)
            ControlDisable("********", "", $Button2)
            ControlEnable("********", "", $Button3)
            $lines = GUICtrlRead($Input2)
            $file_get = GUICtrlRead($Input1)
            $random1 = Random(1, _FileCountLines($file_get), 1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Error #003 at " & @error & @CRLF & "This Error most likey means that there was an error reading how many lines the file has." & @CRLF & "The program will continue, but other errors may occure.")
            EndIf
            If FileExists($file_get) Then
                $moveon = 1
            Else
                $moveon = 0
            EndIf
            If $moveon = 1 Then
                $file = FileOpen($file_get, 1)
                If @error Then
                    MsgBox(48, "Error", "The program has encountered an error. Error #004 at" & @error)
                    Exit
                EndIf
                    GUICtrlSetData($Label2, "Completed: " & $i & " of " & $lines)
                    GUICtrlSetData($Label3, "Line: " & $random1)
                    Do
                        _StopCheck(0)
                            $i = $i + 1
                            $random1 = Random(1, _FileCountLines($file_get) + 1, 1)
                            $random2 = Random(1, 50000, 1)
                            ;************
                            If @error < 0 Then
                                $msgbo = MsgBox(4, "Error - " & @error, "We have encountered an error while ****** the file. The program will be forced to exit." & @CRLF & "Erase file contents?")
                                If $msgbo = 6 Then
                                    FileClose($file)
                                    $file = FileOpen($file_get, 2)
                                    MsgBox(0, "Complete", "Contents erased. Program exiting.")
                                    $i = 1000
                                    Exit
                                Else
                                    $i = 1000
                                    Exit
                                EndIf
                            EndIf
                            GUICtrlSetData($Label2, "Completed: " & $i & " of " & $lines)
                            GUICtrlSetData($Label3, "Line: " & $random1)
                            GUICtrlSetData($Label4, "Wrote: " & $random2)
                    Until $i = $lines
                    $i = 0
                    FileClose($file)
                    MsgBox(0, "Complete", "******** Complete.")
                    Sleep(10)
            Else
                MsgBox(48, "Error", "The selected file cannot be found. Please select a different file...") 
            EndIf
        Case $Button3
            _StopCheck(1)
    EndSwitch
WEnd

Func _StopCheck($stop)
    If $stop = 1 Then
        $i = $lines
    EndIf
EndFunc

Can somebody tell me why the stop button won't work?

(Sorry, had to blank out some words... (*****))

Edited by Firestorm

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

First of all, do the other buttons work?

I think it may lie somewhere in how you did the Switch-EndSwitch

I keep getting an error about it.

Edited by BALA

[font="Comic Sans MS"]BA-LA[/font]http://ba-la.110mb.comJoin my community, CLICK HEREAlternative links to my site:http://www.ba-la.tkhttp://www.ba-la.co.nrContact me if you would like to help with some of my projects: joeythepirate@gmail.com

Share this post


Link to post
Share on other sites

First of all, do the other buttons work?

I think it may lie somewhere in how you did the Switch-EndSwitch

I keep getting an error about it.

What error exactly?

Suggest using OnEvent for the button to work during the loops.

I can't figure this out...If I place the Opt near the top of the script, none on my buttons will work, and it won't close. So I placed it in the button ($button2) and then I have GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_StopCheck") within the loop, but nope. It's not working... :P

#include <GUIConstants.au3>
#include <File.au3>
#include <String.au3>
Global $msgbo
$stop = 0
$moveon = 0
$i = 0
$random1 = 0
$pause = 0
$Form1 = GUICreate("*********", 574, 211, 193, 115)
$Input1 = GUICtrlCreateInput("Type file address or click browse...", 112, 32, 433, 21)
$Button1 = GUICtrlCreateButton("Browse", 24, 16, 81, 25, 0)
$Button2 = GUICtrlCreateButton("Start***", 24, 48, 81, 25, 0)
$Label1 = GUICtrlCreateLabel("Number of Lines to ******:", 120, 56, 133, 17)
$Input2 = GUICtrlCreateInput("1000", 256, 56, 57, 17)
$Group1 = GUICtrlCreateGroup("*********", 184, 112, 177, 97)
$Label2 = GUICtrlCreateLabel("Completed:", 200, 136, 160, 17)
$Label3 = GUICtrlCreateLabel("Line: ", 200, 160, 160, 17)
$Label4 = GUICtrlCreateLabel("Wrote: ", 200, 184, 160, 17)
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Button3 = GUICtrlCreateButton("Stop *********", 376, 168, 91, 25, 0)
ControlDisable("Corruptor", "", $Button3)
GUISetState(@SW_SHOW)


While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            $file_browse = FileOpenDialog("Select a File", "", "All(*.*)", 1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Please select a different file, or restart the program.")
            Else
                GUICtrlSetData($Input1, $file_browse)
            EndIf
        Case $Button2
            Opt("GUIOnEventMode", 1)
            ControlDisable("*********", "", $Button1)
            ControlDisable("*********", "", $Button2)
            ControlEnable("*********", "", $Button3)
            $lines = GUICtrlRead($Input2)
            $file_get = GUICtrlRead($Input1)
            $random1 = Random(1, _FileCountLines($file_get), 1)
            If @error Then
                MsgBox(48, "Error", "The program has encountered an error. Error #003 at " & @error & @CRLF & "This Error most likey means that there was an error reading how many lines the file has." & @CRLF & "The program will continue, but other errors may occure.")
            EndIf
            If FileExists($file_get) Then
                $moveon = 1
            Else
                $moveon = 0
            EndIf
            If $moveon = 1 Then
                $file = FileOpen($file_get, 1)
                If @error Then
                    MsgBox(48, "Error", "The program has encountered an error. Error #004 at" & @error)
                    Exit
                EndIf
                    GUICtrlSetData($Label2, "Completed: " & $i & " of " & $lines)
                    GUICtrlSetData($Label3, "Line: " & $random1)
                    Do
                        GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_StopCheck")
                            $i = $i + 1
                            $random1 = Random(1, _FileCountLines($file_get) + 1, 1)
                            $random2 = Random(1, 50000, 1)
                            ;***************************
                            If @error < 0 Then
                                $msgbo = MsgBox(4, "Error - " & @error, "We have encountered an error while ********* the file. The program will be forced to exit." & @CRLF & "Erase file contents?")
                                If $msgbo = 6 Then
                                    FileClose($file)
                                    $file = FileOpen($file_get, 2)
                                    MsgBox(0, "Complete", "Contents erased. Program exiting.")
                                    $i = $lines
                                    Exit
                                Else
                                    $i = $lines
                                    Exit
                                EndIf
                            EndIf
                            GUICtrlSetData($Label2, "Completed: " & $i & " of " & $lines)
                            GUICtrlSetData($Label3, "Line: " & $random1)
                            GUICtrlSetData($Label4, "Wrote: " & $random2)
                    Until $i = $lines
                    $i = 0
                    FileClose($file)
                    MsgBox(0, "Complete", "Corruption Complete.")
                    Opt("GUIOnEventMode", 0)
                    Sleep(10)
            Else
                MsgBox(48, "Error", "The selected file cannot be found. Please select a different file...") 
            EndIf
        Case $Button3
            _StopCheck(1)
            ControlEnable("*********", "", $Button1)
            ControlEnable("*********", "", $Button2)
            ControlDisable("*********", "", $Button3)
    EndSwitch
WEnd

Func _StopCheck($stop)
    If $stop = 1 Then
        $i = $lines
    EndIf
EndFunc

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Share this post


Link to post
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
Sign in to follow this  
Followers 0