maniootek Posted February 26, 2015 Share Posted February 26, 2015 (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 February 26, 2015 by maniootek Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 26, 2015 Moderators Share Posted February 26, 2015 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?") EndFuncM23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maniootek Posted February 26, 2015 Author Share Posted February 26, 2015 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 Link to comment Share on other sites More sharing options...
Danyfirex Posted February 26, 2015 Share Posted February 26, 2015 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 Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted February 26, 2015 Moderators Solution Share Posted February 26, 2015 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 ;==>_WarningThis works because AutoIt will not run the _Warning function at all if @error is not set - a nice "feature"! M23 maniootek 1 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maniootek Posted February 26, 2015 Author Share Posted February 26, 2015 yes, genius Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted February 26, 2015 Moderators Share Posted February 26, 2015 maniootek,Thanks - I was quite pleased myself! 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
maniootek Posted February 26, 2015 Author Share Posted February 26, 2015 (edited) maniootek, Thanks - I was quite pleased myself! 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 February 26, 2015 by maniootek Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now