Suppose you are executing a function in a *for_each() statement, something like
list = <<%txt%
line1
line2
line3
%txt%
list2 = ""
list2 = *for_each(foo,upper(foo.value),list)
? list2
= LINE1
LINE2
LINE3
With a short list you probably don't want a message displayed telling the progress but for a longer list you might.
If you have a function like pleasewait() (included below, originally designed by Jerry Brightbill) that returns the same data type you can concatenate the two functions in the *for_each().
*for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
This statement should be immediately followed with a statement that closes the final pleasewait() dialog.
*for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
ui_modeless_dlg_close("Processing")
Since Alpha performs automatic data type conversion when concatenating other values with character values you can concatenate a date, numeric, or logical return function with one that returns a character value like pleasewait(). If you attempt concatenate other types an error is returned, (ERROR: Argument is incorrect data type). If you do use this functionality you will be responsible for converting the results back to the proper data type you intended.
If you want to test the pleasewait() in the interactive window you can start with the code above. To create a longer list to use with the pleasewait() and see the dialog use the following after first running the list assignment above.
for qx = 1 to 10
list = list + list
next qx
then
list2 = ""
list2 = *for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
ui_modeless_dlg_close("Processing")
? list2
Why does this work? When Alpha encounters
upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value)
both functions must be evaluated. Since the second function performs the "Processing" dialog, the dialog is displayed. The return value of pleasewait() is a blank or null so it does not interfere with the result of the upper() function.
FUNCTION PleaseWait AS C (Show = .F.,what = "" )
'DESCRIPTION: This function displays a 'Please Wait' dialog for use while processing.
'What is an optional parameter that will be displayed along with the words "Please Wait"
PleaseWait = ""
if show = .F.
if ui_modeless_dlg_exist("Processing")
ui_modeless_dlg_close("Processing")
end if
exit function
end if
text1 = what+" Please Wait"
len = len(text1)*2
textbox="{text="+alltrim(str(len))+"text1}"
box_code = <<%dlg%
{background=Pale Yellow}
{font=arial,14,bi}
{include=textbox}
%dlg%
box_event = <<%code%
1=1
'sleep(5)
%code%
ui_modeless_dlg_box("Processing",box_code,box_event)
ui_modeless_dlg_setfocus("Processing")
ui_modeless_dlg_refresh("Processing")
END FUNCTION
list = <<%txt%
line1
line2
line3
%txt%
list2 = ""
list2 = *for_each(foo,upper(foo.value),list)
? list2
= LINE1
LINE2
LINE3
With a short list you probably don't want a message displayed telling the progress but for a longer list you might.
If you have a function like pleasewait() (included below, originally designed by Jerry Brightbill) that returns the same data type you can concatenate the two functions in the *for_each().
*for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
This statement should be immediately followed with a statement that closes the final pleasewait() dialog.
*for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
ui_modeless_dlg_close("Processing")
Since Alpha performs automatic data type conversion when concatenating other values with character values you can concatenate a date, numeric, or logical return function with one that returns a character value like pleasewait(). If you attempt concatenate other types an error is returned, (ERROR: Argument is incorrect data type). If you do use this functionality you will be responsible for converting the results back to the proper data type you intended.
If you want to test the pleasewait() in the interactive window you can start with the code above. To create a longer list to use with the pleasewait() and see the dialog use the following after first running the list assignment above.
for qx = 1 to 10
list = list + list
next qx
then
list2 = ""
list2 = *for_each(foo,upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value),list)
ui_modeless_dlg_close("Processing")
? list2
Why does this work? When Alpha encounters
upper(foo.value)+PleaseWait(.T.,"Working on - "+foo.value)
both functions must be evaluated. Since the second function performs the "Processing" dialog, the dialog is displayed. The return value of pleasewait() is a blank or null so it does not interfere with the result of the upper() function.
FUNCTION PleaseWait AS C (Show = .F.,what = "" )
'DESCRIPTION: This function displays a 'Please Wait' dialog for use while processing.
'What is an optional parameter that will be displayed along with the words "Please Wait"
PleaseWait = ""
if show = .F.
if ui_modeless_dlg_exist("Processing")
ui_modeless_dlg_close("Processing")
end if
exit function
end if
text1 = what+" Please Wait"
len = len(text1)*2
textbox="{text="+alltrim(str(len))+"text1}"
box_code = <<%dlg%
{background=Pale Yellow}
{font=arial,14,bi}
{include=textbox}
%dlg%
box_event = <<%code%
1=1
'sleep(5)
%code%
ui_modeless_dlg_box("Processing",box_code,box_event)
ui_modeless_dlg_setfocus("Processing")
ui_modeless_dlg_refresh("Processing")
END FUNCTION