maniootek

Return functon1 from function2

8 posts in this topic

#1 ·  Posted (edited)

I have just written some function. Remarks in code is my question.

Func Test()
    ...
    if @error then Warning("Error with test") ;in this step I want call Warning() func and when msgbox popup and if I click "no" then I want return this Test() function instead of Warning() function, possible?
    ...
EndFunc

Func Warning($text)
   $answer = MsgBox(48+4, "Warning!", $text & @CRLF & "Continue?")
   if $answer = 6 then ;6=yes, 7=no
      Return
   Else
      Exit
   EndIf
EndFunc

just tried to use Call() but it doesn't resolve my problem.

Edited by maniootek

Share this post


Link to post
Share on other sites



maniootek,

Perhaps something like this: :)

#include <MsgBoxConstants.au3>

_Test()

MsgBox($MB_SYSTEMMODAL, "Test", "Continuing")

Func _Test()

    SetError(1) ; Force error

    If @error Then
        If _Warning("Error with test") = 6 Then
            Return
        Else
            Exit
        EndIf
    EndIf

EndFunc

Func _Warning($sText)

   Return MsgBox($MB_ICONWARNING + $MB_YESNO, "Warning!", $sText & @CRLF & "Continue?")

EndFunc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

my purpose of this idea is to save some code as I will have many situation where I wanted to use Warning() function. Your idea still mess my code by extra lines like:

Return
Else
Exit
Endif

Share this post


Link to post
Share on other sites

I think something like this.

Test()

Func Test()
    If @error Then
        If Warning("Error with test") = 7 Then
            MsgBox(64, "You will be Exit here", "You will be Exit here")
        Else
            MsgBox(64, "You will continue", "You will continue")
        EndIf

    EndIf
EndFunc   ;==>Test

Func Warning($text)
    Return MsgBox(48 + 4, "Warning!", $text & @CRLF & "Continue?")
EndFunc   ;==>Warning

But remember when you enter to a funtion @error will be set to 0.

Saludos

Share this post


Link to post
Share on other sites

maniootek,

A minimalist version: ;)

#include <MsgBoxConstants.au3>

_Test()

MsgBox($MB_SYSTEMMODAL, "Test", "Continuing")

Func _Test()

    SetError(1) ; Force error

    If @error And _Warning("Error with test") Then Exit

EndFunc   ;==>_Test

Func _Warning($sText)

    If MsgBox($MB_ICONWARNING + $MB_YESNO, "Warning!", $sText & @CRLF & "Continue?") = 6 Then
        Return
    Else
        Exit
    EndIf

EndFunc   ;==>_Warning
This works because AutoIt will not run the _Warning function at all if @error is not set - a nice "feature"! :D

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

yes, genius :thumbsup:

Share this post


Link to post
Share on other sites

maniootek,

Thanks - I was quite pleased myself! :D

You might want to change the _Warning function to return False just to be on the safe side. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

maniootek,

Thanks - I was quite pleased myself! :D

You might want to change the _Warning function to return False just to be on the safe side. ;)

M23

look this code:

#include <MsgBoxConstants.au3>

_Test()

Func _Test()
    SetError(1) ; Force error
    If @error And _Warning("Error with test") Then Return
    MsgBox($MB_SYSTEMMODAL, "Test", "Continuing")
EndFunc   ;==>_Test

Func _Warning($sText)
    If MsgBox($MB_ICONWARNING + $MB_YESNO, "Warning!", $sText & @CRLF & "Continue?") = 6 Then
        Return True
    Else
        Exit
    EndIf
EndFunc   ;==>_Warning

this is even more better for me

added:

as _Warning() function means to return (close) current _Test() function anyway. Exit is optional.

thanks anyway!

Edited by maniootek

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