Alpha Video Training
Results 1 to 10 of 10

Thread: Can enum be used in a UDF for a function parameter?

  1. #1
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Can enum be used in a UDF for a function parameter?

    Hi All

    Is it possible to use one of the enum functions to let me pick from choices in my UDF's instead of having to type certain choices out. For example, I have one function that uses the form name as a parameter I pass to the function and I was hoping to somehow use:

    a5.Form_Enum(2)

    By using the form enum funtion I was hoping to display a list(to me when implementing the function in my code) of the forms in the current app so I could just choose it from a list. I am basically wanting to duplicate Alpha's behavior on certain functions when we are allowed to right click and for example pick the DBF we want to use with the dbcount function.

    Thanks...

    Jeff

  2. #2
    VAR csda1's Avatar
    Real Name
    Ira J Perlow
    Join Date
    Apr 2000
    Location
    Boston, Massachusetts, USA
    Posts
    3,530

    Default Re: Can enum be used in a UDF for a function parameter?

    Hi Jeff,

    Quote Originally Posted by jkletrovets View Post
    Hi All
    Is it possible to use one of the enum functions to let me pick from choices in my UDF's instead of having to type certain choices out. For example, I have one function that uses the form name as a parameter I pass to the function and I was hoping to somehow use:

    a5.Form_Enum(2)

    By using the form enum funtion I was hoping to display a list(to me when implementing the function in my code) of the forms in the current app so I could just choose it from a list. I am basically wanting to duplicate Alpha's behavior on certain functions when we are allowed to right click and for example pick the DBF we want to use with the dbcount function.
    It is possible, but not easy. See this thread Re: UDF Parameters lookup where it was discussed.

    It is easiest, when you can use Alpah's built-in ones by using the same or similar parameter names.
    Regards,

    Ira J. Perlow
    Computer Systems Design


    CSDA A5 Products
    New - Free CSDA DiagInfo - v1.39, 30 Apr 2013
    CSDA Barcode Functions

    CSDA Code Utility
    CSDA Screen Capture



  3. #3
    Member ChrisHawkes's Avatar
    Real Name
    Chris Hawkes
    Join Date
    Apr 2000
    Location
    Dorset, UK
    Posts
    295

    Default Re: Can enum be used in a UDF for a function parameter?

    Hi Jeff

    As Ira says, try to use Alpha's built-in parameters. For forms the form_name parameter should work.

    e.g
    Code:
     
    FUNCTION form_zzTest2 AS C (form_name AS C )
         ui_msg_box("","Form Name Is:- "+form_name)
    END FUNCTION
    If It Works First Time, There's Something Wrong!!!

  4. #4
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: Can enum be used in a UDF for a function parameter?

    Thanks Ira and Chris!

    I appreciate it. That gets done exactly what I wanted to do (using Alpha's built in ones).

    Interesting possibilities with everything discussed in that thread as well.

    Thanks again....

    Jeff

  5. #5
    "Certified" Alphaholic
    Real Name
    Finian Lennon
    Join Date
    Apr 2000
    Location
    Atlanta, GA
    Posts
    1,804

    Default Re: Can enum be used in a UDF for a function parameter?

    This one got me thinking about other uses. So why not do it along the lines of the original conception?

    Dump all this code into a single script.

    Code:
    '============================================
    DIM shared TType as C
    DIM shared varC_result as C
    'insert another xd here with a dropdown of the types you want to process
    'For now just use form
    thistype = "Form"
    ShowType(thistype)
    if varC_result = "OK" then
        ui_msg_box("","Selected " + ttype)
    end if
    '=============================================
    FUNCTION ParseType AS C(AType as C,Name = "" )
    'Pass the alpha "type" to the function so that it can be parsed
    'if the type and name are passed just process the name
    if alltrim(name) <> "" then
     'do something with this object
    end if
    'get the list
    dim objlist as c
    ParseType = alltrim(sortsubstr(eval("A5." + AType + "_enum(2)"),Crlf(),"A"))
    END FUNCTION
    '=============================================
    Function ShowType as C(BType as C)
    dim shared ttype as c
    auto_list_TType = ParseType(Btype)
    temp_count = w_count(auto_list_TType,crlf())
    DELETE a_TType
    DIM a_TType[temp_count] as c
    a_TType.initialize(auto_list_TType)
    ok_button_label = "&OK"
    cancel_button_label = "&Cancel"
    dlg_title = "Select"
    dlg_code=<<%dlg%
    {region}
    Select:| [%v%.37TType^+a_TType];
    {endregion};
    {line=1,0};
    {region}{justify=center}
    <*15=ok_button_label!OK> <15=cancel_button_label!CANCEL>
    {endregion};
    %dlg%
    
    event_code=<<%code%
    if a_dlg_button = "Cancel" then
        g1 = ui_msg_box("","Nothing selected." + Crlf(2) + "Continue to exit?",ui_yes_no)
        	if g1 = ui_no_selected then
        	    a_dlg_button = ""
        	end if
    end if
    %code%
    varC_result = ui_dlg_box(dlg_title,dlg_code,event_code)
    END FUNCTION
    '=============================================
    Just a thought.
    Finian

  6. #6
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: Can enum be used in a UDF for a function parameter?

    Yup,
    I made this one for a section of a function which allows a choice of db tables and then presented with the table fields, similar to the code editor's code> insert field name menu option. Thought I would throw this in the mix.

    Code:
    ' get list of the current tables
    dim vTM as C=""
    vTM = a5.table_enum()
    dim vFM as C=""
    
    '======== generate the xDialogs ===================
    dim tablename as C
    dim fieldname as C = "Field Name"
    dim shared vdy as C
    
    	dlg_text = <<%dlg%
    	{position=1.5,2.5}
    	{background=#170,200,175}
    	{xmargin=2,2}
    	{font=Arial,9,b}
    	{frame=1,1: Tables and Fields}
    	{font=Arial,9,n}
    	{region}
    	[.25,20tablename^#vTM!tc_*] {sp} | [.25,20fieldname^#vFM!fc_*]
    	{endregion};
    	{lf};
    	{condition=.t.}
    	{line=1,0}
    	{lf};
    	{justify=center}<10OK> <10Cancel>
    	%dlg%
    	
    	dim vresults as C 
    RETRY:	
    	vresult=ui_dlg_box("Item Choices", dlg_text, <<%code%
    
    	' this is for a trapping a change in the tablefield box
    	IF left( a_dlg_button, 3 ) = "tc_"
    	 IF a_dlg_button = "tc_change"
    	 	vFM = sortsubstr(w_upper(lower(table.external_field_name_get(tablename,"N"))),crlf(),"a")
    	 END IF
     		 a_dlg_button = ""
    	END IF
    	%code%)
    	
    	' process selections
    	if vresult = "Cancel"
    		end
    	else if tablename = ""
    		ui_msg_box("SELECTION ERROR","There was no table selected. Please try again",48)
    		GOTO RETRY
    	else if fieldname = "Field Name"
    		ui_msg_box("SELECTION ERROR","There was no field selected. Please try again",48)
    		GOTO RETRY
    	end if
    
    msgbox("Choices","Table = " + alltrim(tablename)+crlf()+"Field = " + alltrim(fieldname))
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  7. #7
    "Certified" Alphaholic
    Real Name
    Cal Locklin
    Join Date
    Mar 2000
    Location
    S.E. Michigan
    Posts
    5,763

    Default Re: Can enum be used in a UDF for a function parameter?

    Holy Cow! Maybe I truly am the only one in Alphadom that likes to see fields listed in natural order. My reasons:
    (A) I tend to group them by things like --> "key fields" (at the beginning), "address info", "phones", "shipping info", "billing info", "special price info", "contact info", etc. Sometimes, having them scattered all over in the list is a pain.
    (B) new fields are almost always added at the end of the table but I don't always remember the name of those newer fields. Searching for "I don't remember the field name" alphabetically is rather difficult.

    This has been one of my pet peeves with A5 for a long time. Some dialogs only show fields in alphabetic order, some only show them in natural order, and a few actually allow the developer a choice. I think they should ALL allow a choice - something that should be very easy to do. It was certainly easy to do here.

    And, yes, sometimes I do like to see them presented alphabetically. I just want the choice!

    Here's a revision to Mike's script that allows the user to choose the sort order. It is also modified to eliminate the "Restart" and just keep it in the dialog unless the user selects both the table and field name: (script layout reformatted with my free Script_Formatter)
    Code:
    ' get list of the current tables
    DIM vTM as C = ""
    vTM = a5.table_enum()
    DIM vFM as C = ""
     
    '======== generate the xDialogs ===================
    DIM tablename as C
    DIM fieldname as C = "Field Name"
    DIM SHARED vdy as C
    sort_alpha = .T.
    
    dlg_text = <<%dlg%
    {position=1.5,2.5}
    {background=#170,200,175}
    {xmargin=2,2}
    {font=Arial,9,b}
    {frame=1,1: Tables and Fields}
    {font=Arial,9,n}
    {region}
    {font=Arial,8,b} Select Table: | Select Field:{font=Arial,9,n} (sort_alpha!tc_*?tablename!="")Sort Alpha;
     [.29,20tablename^#vTM!tc_*] | [.29,20fieldname^#vFM!fc_*]
    {endregion};
    {lf};
    {line=1,0}
    {lf};
    {justify=center}<10OK> <10Cancel>
    %dlg%
    
    DIM vresults as C
    vresult = ui_dlg_box( "Item Choices", dlg_text, <<%code%
    ' this is for a trapping a change in the tablefield box
    IF left( a_dlg_button, 3 ) = "tc_"
    	IF a_dlg_button = "tc_change"
    		IF sort_alpha
    			vFM = sortsubstr( w_upper( lower( table.external_field_name_get( tablename, "N" ) ) ), crlf(), "a" )
    		ELSE
    			vFM = w_upper( lower( table.external_field_name_get( tablename, "N" ) ) )
    		END IF
    	END IF
    	a_dlg_button = ""
    ELSEIF left( a_dlg_button, 3 ) = "fc_"
    	IF a_dlg_button = "fc_change"
    		a_dlg_button = "OK"
    	ELSE
    		a_dlg_button = ""
    	END IF
    END IF
    IF a_dlg_button = "OK"
    	IF tablename = ""
    		ui_msg_box( "SELECTION ERROR", "There was no table selected. Please try again", 48 )
    		a_dlg_button = ""
    	ELSEIF fieldname = "Field Name"
    		ui_msg_box( "SELECTION ERROR", "There was no field selected. Please try again", 48 )
    		a_dlg_button = ""
    	END IF
    END IF
    %code% )
    
    ' process selections
    IF vresult <> "OK"
    	END'
    END IF
    
    msgbox( "Choices", "Table = " + alltrim( tablename ) + crlf() + "Field = " + alltrim( fieldname ) )
    Last edited by CALocklin; 05-15-2009 at 02:50 PM. Reason: Fixed problems with my original script changes.

  8. #8
    "Certified" Alphaholic Mike Wilson's Avatar
    Real Name
    mike wilson
    Join Date
    Apr 2005
    Location
    Grand Rapids, Michigan
    Posts
    4,198

    Default Re: Can enum be used in a UDF for a function parameter?

    Cal,
    Excellent addition, thank you. It works perfectly in my hands. Yes, I group fields in the table also, and this does assist in locating the desired field. Nice job.
    Mike W
    __________________________
    "I rebel in at least small things to express to the world that I have not completely surrendered"

  9. #9
    "Certified" Alphaholic
    Real Name
    Jeff Kletrovets
    Join Date
    Oct 2005
    Location
    Columbus, OH
    Posts
    1,135

    Default Re: Can enum be used in a UDF for a function parameter?

    Sorry for my delay in responding back to this post....I have been out of town.

    This is VERY cool stuff and in my mind opens up a whole new area of possibility for my functions. Yes Ira...you have turned me into a function fanatic now! :)

    I am working on a "framework" that I will use to start every application that contains my core application functions (auto-increment, custom req'd field checking, opening child table data entry forms, a couple standard "starter forms" etc.)

    I have not had a chance to test this yet but if I am reading all the posts correctly.....then I should be able to just call these various enum functions in the following section in my function:

    addin.function_argument_help
    Does that sound correct?

    So, a typical use for me might be something like this in a UDF called AddChild():

    From the help file...
    <FORM> as P = FORM.LOAD( Form_Name as C [, Style as C [, Window_Name as C [, Horizontal_Position as N [, Vertical_Position as N ]]]] )
    ...and "Childform" argument below can then be picked using a msgbox or dropdown similar to Alpha's built in function helpers. Function below is just skeleton code for this example....

    Code:
    FUNCTION AddChild as C (Childform as C)
    addin.function_argument_help=(Call function to list all forms in app for my help when implementing function in my app)
    
    DIM formptr as P
    formptr = FORM.LOAD(childform, "dialog","","Center","Center")
    formptr.new_record()
    formptr.show()
    
    
    END FUNCTION
    Thoughts?

    Thanks...

    JK

  10. #10
    "Certified" Alphaholic
    Real Name
    Mike Christensen
    Join Date
    Nov 2005
    Location
    Michigan U.P.
    Posts
    5,937

    Default Re: Can enum be used in a UDF for a function parameter?

    Hi Jeff,

    I had a page or reply and then Mozilla crashed and lost it! :(

    Gist of it as I have to leave---check out the prior thread given as reference earlier. I believe I gave a list by Selwyn of the addin.function_argument_help Alpha uses and you can use those as guides to build your own.

    addin.function_argument_help is used to give a function's arguments more "functionality" such as dropdowns, lists, values, etc.. it can be anything that you can add in a single line via xbasic really.

    Better to use built-in Alpha methods as less headaches overall. addin.function_argument_help has to be run at least once prior to function being used in order for it to work.

    You will find that mods made to a function that includes the addin.function_argument_help inside it will not show the mods made until you exit and reenter the database.

    had more but gotta go!!!! If any questions just holler as you know I will be checking back in! :)
    Mike
    __________________________________________
    It is only when we forget all our learning that we begin to know.
    It's not what you look at that matters, it's what you see.
    Henry David Thoreau
    __________________________________________




Similar Threads

  1. AEX udf/script enum method?
    By Peter.Greulich in forum Alpha Five Version 8
    Replies: 3
    Last Post: 11-12-2014, 11:20 PM
  2. Skip parameter in UDF
    By Bill Parker in forum Archived Wishlist
    Replies: 5
    Last Post: 03-11-2006, 09:39 AM
  3. Xbasic - Some type of ENUM function
    By KeithW in forum Alpha Five Version 6
    Replies: 10
    Last Post: 09-22-2005, 06:51 PM
  4. Function Parameter calling bug?
    By csda1 in forum Alpha Five Version 5
    Replies: 0
    Last Post: 07-29-2004, 10:48 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •