Flylib.com

Books Software

 
 
 

Create a Formatted Date String


Create a Formatted Date String

This routine illustrates how to create a formatted date string that includes the day of the week, month, day, and year (e.g., Friday April 14, 2006).

How It Works

The formatted date is computed with a combination of the @Today , @Weekday , @Year , @Month , and @Day functions. The returned values are subsequently used to create the formatted date string, which is stored in the theDate variable.

Implementation

To implement this solution, insert the following formula in an action button, column, or default value for a field. Optionally, replace @Today with a date or field. The @Prompt statement is used for illustrative purposes and can be removed or updated as desired. However, if removed, be sure the formula contains a main expression (i.e., Result ) as the last statement in the formula.

theDate := @Today;

theWeekday := @Select(@Weekday (theDate);
            "Sunday"; "Monday";
            "Tuesday"; "Wednesday";
            "Thursday"; "Friday";
            "Saturday"
            );

theMonth := @Select(@Month(theDate);
            "January"; "February"; "March";
            "April"; "May"; "June";
            "July"; "August"; "September";
            "October"; "November"; "December"
             );

theDay := @Text (@Day (@Today));

theYear := @Text (@Year (theDate));

result := "Today is " +
theWeekday + " " +
theMonth + " " +
theDay + ", " +
theYear;

@Prompt([Ok];"Result"; result);


Figure 14.5 depicts the result when implemented in an action button.

Figure 14.5. Example of a formatted date string




Create an Attach File Button

Creating an Attach File button for an application provides the ability to insert files into the intended field. This routine prompts the user to select a file from the file finder and insert the file into the specified field.

How It Works

When the button is clicked, the cursor jumps to the specified field and launches the file finder. If the user selects a file, it is inserted in the specified field. In order to implement this solution, the target field must be set to Rich Text. Also note that the document must be in edit mode in order for the selected file to be applied to the designated field.

Note

You can also use Rich Text Lite, which by default will place a button next to the field.


Implementation

To implement this technique, create a Rich Text field on a form and make note of the field name. Next, create an action button and name it Attach File . To ensure that the button is only available when the document is in edit mode, set the "Hide When" properties for the button (see Figure 14.6).

Figure 14.6. Hide property settings for an action button


Finally, insert the following formula in the Programmer's pane. Replace FIELDNAME with the name of a Rich Text field on the form.

@Command([EditGotoField]; "

FIELDNAME

");
@Command([EditInsertFileAttachment])


Note

If the document is not in edit mode or there is no Rich Text field on the form, the error message shown in Figure 14.7 will most likely display.


Figure 14.7. Error when attempting to attach a file to a document in read mode




Display the Windows File Finder Dialog

The file finder dialog allows users to locate and select a workstation file. After a file has been selected, you can attach the file to a field, store the file location, or use the value in a formula. Figure 14.8 depicts the file finder dialog.

Figure 14.8. Example of the Windows file finder dialog


How It Works

The @Prompt command includes a LocalBrowse parameter that displays the Windows file finder dialog. The fully qualified path and the file name are then stored in the document field specified in the formula.

Implementation

To implement this solution, create a field on a form. Next, create a button on the form and insert the following formula, making sure to replace FIELDNAME with the actual name of the field on the form.

FIELD

FIELDNAME

:= @Prompt([LocalBrowse];"Select a file";"");
@Prompt([Ok];"Selected file";

FIELDNAME

)