Jump to content

Return functon1 from function2


 Share

Go to solution Solved by Melba23,

Recommended Posts

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
Link to comment
Share on other sites

  • Moderators

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

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

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

Link to comment
Share on other sites

  • Moderators
  • Solution

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

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

  • Moderators

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

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

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