Jump to content

While 1 inside function?


 Share

Recommended Posts

Hello guys,

Is there any way to exit from while loop inside any function trough a contol button ?

e.g :

i have a 1 button in GUI to call "search function"

the "search function" use while 1 loop.

now i want to stop that loop from Pause button.

So how can i complete this task?

i tried it but , when i call "search funtion" im not able to exit from the loop until the loops end.

Thanks in Advance for your help.

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Supply some script and it will be easier to help.

i know this example in GUI but thats a short example of my current project.

global $g = 0

$s_window= GUICreate("Search window", 550, 400, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "on_exit")

$crnt_file = GUICtrlCreateLabel("", 48, 104, 489, 33,$SS_LEFTNOWORDWRAP)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT

$start = GUICtrlCreateButton("start", 425, 370, 54, 25)
GUISetOnEvent($start, "start_sch")

$pause = GUICtrlCreateButton("Pause", 425, 370, 54, 25, BitOR($BS_FLAT,$BS_BITMAP))
GUISetOnEvent($start, "pause_sch")

while 1
sleep(1000)
wend

Func start_sch()
Search("D:\","*.*")
EndFunc

Func pause_sch()
$g = 1
Endfunc

Func Search($current,$toFind)
    If $g <> 1 Then
    If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)
    Local $search = FileFindFirstFile($current & "\*.*")
    While 1
        
        
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            
        GUICtrlSetData($crnt_file,$current& "\" &$file)
        Sleep(10)

        ConsoleWrite(@CRLF&"+>"&$i&"File Name "&$current& "\" &$file)
            IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file)
                
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file, $toFind)
            
        EndIf
        
    WEnd
    FileClose($search)
EndIf
EndFunc
Edited by Digisoul

73 108 111 118 101 65 117 116 111 105 116

Link to comment
Share on other sites

Try this:

global $g = 0
global $bStop = 0

$s_window= GUICreate("Search window", 550, 400, -1, -1, -1, BitOR($WS_EX_APPWINDOW, $WS_EX_WINDOWEDGE))
GUISetOnEvent($GUI_EVENT_CLOSE, "on_exit")

$crnt_file = GUICtrlCreateLabel("", 48, 104, 489, 33,$SS_LEFTNOWORDWRAP)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT

$start = GUICtrlCreateButton("start", 425, 370, 54, 25)
GUISetOnEvent($start, "start_sch")

$pause = GUICtrlCreateButton("Pause", 425, 370, 54, 25, BitOR($BS_FLAT,$BS_BITMAP))
GUISetOnEvent($start, "pause_sch")

while 1
sleep(1000)
wend

Func start_sch()
Search("D:\","*.*")
EndFunc

Func pause_sch()
$bStop = 1
$g = 1
Endfunc

Func Search($current,$toFind)
    If $g <> 1 Then
    If StringRight($current,1) = "\" then $current = StringTrimRight($current,1)
    Local $search = FileFindFirstFile($current & "\*.*")
    While not $bStop
        
        
        Dim $file = FileFindNextFile($search)
        If @error Or StringLen($file) < 1 Then ExitLoop
        If Not StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            
        GUICtrlSetData($crnt_file,$current& "\" &$file)
        Sleep(10)

        ConsoleWrite(@CRLF&"+>"&$i&"File Name "&$current& "\" &$file)
            IF $file = $toFind then Msgbox(0,"File found", $current & "\" & $file)
                
        EndIf
        If StringInStr(FileGetAttrib($current & "\" & $file), "D") And ($file <> "." Or $file <> "..") Then
            Search($current & "\" & $file, $toFind)
            
        EndIf
        
    WEnd
    FileClose($search)
EndIf
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...