Jump to content

Recommended Posts

Posted

I created a GUI UDF() I called PickList() that returns the chosen value from the "pick list".

Is there a prefered way to RETURN a value from the GUI and use GuiDelete() ?

If I simply issue the GuiDelete() before RETURN, my return value is lost.

OR

Am I worring too much about using GUIDelte()?. The GUI does go away when the UDF is finished without using GuiDelete(), but I thought it is considered good form to call GuiDelete() at the end of a program to "clean up".

thanks in advance.

Jim Rumbaugh

Posted (edited)

You could do something like this >>

Local $hWnd = GUICreate(...
Local $iControl = GUICtrlCreateCombo(...

Local $sSelectedText = ''
_PickList($hWnd, $iControl, $sSelectedText)
MsgBox(4096, '', $sSelectedText)

; Using ByRef to pass a reference to a variable
Func _PickList($hWnd, $iControl, ByRef $sSelectedText)
    $sSelectedText = GUICtrlRead($iControl)
    Return GUIDelete($hWnd)
EndFunc   ;==>_PickList

Local $hWnd = GUICreate(...
Local $iControl = GUICtrlCreateCombo(...

_PickList($hWnd, $iControl)
MsgBox(4096, '@error: ' & @error, $sSelectedText)

; Using SetError.
Func _PickList($hWnd, $iControl)
    Local $sSelectedText = GUICtrlRead($iControl)
    Return SetError(GUIDelete($hWnd) = 0, 0, $sSelectedText)
EndFunc   ;==>_PickList
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

guinness

Thanks for your suggestions. They gave me an idea that I perfer to use. I did test it and it worked. ( after I also tried some combos that did NOT work )

... pseudo code goes here
... function ends with call to my new UDF()
Return  _CloseGui( $GuiHundle ,  GUICtrlRead($mylist) )

Func _CloseGui( $nGuiHandle , $Return )
     GUIDelete( $nGuiHandle ) 
     Return $Return
EndFunc

I consider my question answered,

but will take other suggestions.

Posted (edited)

With that snippet I would just settle for this >>

... pseudo code goes here
... function ends With call To my new UDF()
Return _CloseGUI($hWnd, $iMyList)

Func _CloseGUI(ByRef Const $hWnd, ByRef Const $iControl)
    Local $sReturn = GUICtrlRead($iControl)
    GUIDelete($hWnd)
    Return SetError($sReturn = '', 0, $sReturn)
EndFunc   ;==>_CloseGUI
Edited by guinness

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

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
×
×
  • Create New...