How To Define your Own Helpers for Function Arguments in User Defined Functions

Description

Learn how to define helpers for function arguments for user defined functions in desktop applications.

Discussion

Assume you have defined the following UDF in the code editor.

function myFunc as c(arg1 as c, arg2 as c , arg3 as c , arg4 as n )
    myFunc = "test"
end function

Now, when you are writing code and you type myFunc( in the code editor, you would like to provide pick-lists or genies for the function arguments. This can be done easily using the addin.function_argument_help() method.

This method takes these arguments:

  • name of the function parameter
  • description
  • an Xbasic expression that returns a CRLF delimited list of choices, or that displays a dialog that returns a value.
  • a code (=, Q, =Q, A, AQ)

If the code contains 'Q' the function parameter will be quoted when it is inserted into your code.

If the code contains = the Xbasic expression is expected to display an Xdialog to prompt for a value.

If the code does not contain =, the expression is expected to return a crlf list of choices

If the code contains A, the crlf delimited list of choices is in the form 'displayvalue=returnvalue'

'each of the commands below are a single line - line breaks are for readability only

'when user right clicks on 'arg1' a ui_get_text() dialog is shown.
addin.function_argument_help( "arg1" , "helper arg1","ui_get_text('Enter argument','argValue')","=Q","")

'choices shown to user are 'alpha', 'beta', 'gamma'. Value entered into function is

'quoted
addin.function_argument_help( "arg2" , "helper arg2","comma_to_crlf(\"alpha,beta,gamma\)","Q","")

'choices shown to user are 'First','Last' and 'Closest'. Value entered into function
'when user makes a selection is 'F', 'L' or 'C' (quoted)
addin.function_argument_help( "arg3" , "helper for my argument","comma_to_crlf(\"First=F,Last=L,Closest=C\")" , "AQ","")

'choices shown to user are 'First','Last' and 'Closest'. Value entered into function
'when user makes a selection is 1, 2 or 3 (unquoted)
addin.function_argument_help( "arg4" , "helper for my argument","comma_to_crlf(\"First=1,Last=2,Closest=3\")" , "A","")

The addin.function_argument_help() statements would typically be included in your Autoexec script. Once you have executed an addin.function_argument_help() statement, you cannot override it by executing the command a second time. You must exit and restart Alpha Anywhere.

Limitations

Desktop Applications Only