Jump to content

"Stop" a Func()


Recommended Posts

Hi all i have a script with several func()

I have stripped the code in a example like this:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("Form1", 255, 237, -1, -1)
$Button = GUICtrlCreateButton("Button1", 32, 80, 81, 33)
$Input = GUICtrlCreateInput("", 120, 88, 97, 21)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button
   MyFunc()
EndSwitch
WEnd

Func MyFunc()
_IsEmpty()
MsgBox(0,0,"etc.")
EndFunc

Func _IsEmpty()
If GUICtrlRead($Input) = "" Then
  MsgBox(16, "Error", "Empty", 0, $hForm)
  Return
EndIf
EndFunc

Why When i have the Error MsgBox the Return don't stop the script? If i make in this way work:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("Form1", 255, 237, -1, -1)
$Button = GUICtrlCreateButton("Button1", 32, 80, 81, 33)
$Input = GUICtrlCreateInput("", 120, 88, 97, 21)
GUISetState(@SW_SHOW)

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit
  Case $Button
   MyFunc()
EndSwitch
WEnd

Func MyFunc()
If GUICtrlRead($Input) = "" Then
  MsgBox(16, "Error", "Empty", 0, $hForm)
  Return
EndIf
MsgBox(0, 0, "etc.")
EndFunc   ;==>MyFunc

But i'd like to make a separate Func() because i need to check te same things for other Func() and i don't wont to write the same thing many times. Where is my mistake?

Thanks to all

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

OliverA,

Get the _IsEmpty function to return a flag indicating the result - then you can use that flag to determine what to do next: ;)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

$hForm = GUICreate("Form1", 255, 237, -1, -1)
$Button = GUICtrlCreateButton("Button1", 32, 80, 81, 33)
$Input = GUICtrlCreateInput("", 120, 88, 97, 21)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button
            MyFunc()
    EndSwitch
WEnd

Func MyFunc()
    If _IsEmpty() = True Then
        Return
    Else
        MsgBox(0, 0, "etc.")
    EndIf
EndFunc   ;==>MyFunc

Func _IsEmpty()
    If GUICtrlRead($Input) = "" Then
        MsgBox(16, "Error", "Empty", 0, $hForm)
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_IsEmpty

All clear? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Melba thanks, but if i have more then one in the same _IsEmpty like:

If GUICtrlRead($Input) = "" Then
  MsgBox(16, "Error", "Empty", 0, $hForm)
  Return
EndIf
If GUICtrlRead($Input2) = "" Then
  MsgBox(16, "Error", "Empty", 0, $hForm)
  Return
EndIf
If GUICtrlRead($Input3) = "" Then
  MsgBox(16, "Error", "Empty", 0, $hForm)
  Return
EndIf

How i can do?

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

OliverA,

I would do something like this: :)

#include <GUIConstantsEx.au3>

Global $aInput[4] = [3]

$hGUI = GUICreate("Test", 500, 500)

$cButton = GUICtrlCreateButton("Check", 10, 10, 80, 30)

$aInput[1] = GUICtrlCreateInput("", 10, 50, 200, 20)
$aInput[2] = GUICtrlCreateInput("", 10, 70, 200, 20)
$aInput[3] = GUICtrlCreateInput("", 10, 90, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $cButton
            ; See what the function returns
            If _Check_Inputs() = True Then
                MsgBox(64, "Checked", "All inputs valid")
            Else
                MsgBox(48, "Checked", "Some inputs invalid")
            EndIf
    EndSwitch

WEnd

Func _Check_Inputs()

    ; Set a flag
    $fCorrect = True
    ; Now check the inputs
    For $i = 1 To $aInput[0]
        If GUICtrlRead($aInput[$i]) = "" Then
            MsgBox(48, "Error", "Check box " & $i & " is empty")
            ; Clear the flag
            $fCorrect = False
        EndIf
    Next
    ; And return the flag
    Return $fCorrect

EndFunc

Does that fit the bill? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Sure, thanks

I'M QUIT FROM THIS FORUM!

It was fun until it lasted, hope on my future way i can't find people that offend without any reason ( i was called lazy and parasitic, and everyone agreed...United we stand, divided we fall ) just for fun because don't have anything to do in the life, without knowing anything about the person who write, noone forced to post, noone forced to help.

From the top of the from their very great superiority they not go down to my level, that people can not spread the knowledge but you have to learn by yourself.

In what way? It's easy...just search on google

For that people, wish you the best way,

Oliver Astone

Link to comment
Share on other sites

  • Moderators

OliverA,

My pleasure. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...