ex.hlp (Topic list)
Important Notice
The pages on this site contain documentation for very old MS-DOS software, purely for historical purposes. If you're looking for up-to-date documentation, particularly for programming, you should not rely on the information found here, as it will be woefully out of date.
FORMAT$ Function Example
                        Example                Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
' This example illustrates the use of the FORMAT$ function in formatting
' date/time values and numbers.
 
' To try this example:
' 1. Choose New Project from the File menu
' 2. Copy the code example below to the code window
' 3. Press F5 to run the example
 
 DIM message AS STRING
 DIM newline AS STRING
 
 newline$ = CHR$(13) + CHR$(10)          ' Define new line
 mess$ = "Today's date is " + FORMAT$(NOW, "ddddd") + "." + newline$
 mess$ = mess$ + "The current time is " + FORMAT$(NOW, "ttttt")
 mess$ = mess$ + "."
 MSGBOX (mess$)                          ' Display date/time formatting
 VALUE# = INT((4001) * RND - 2000)
 SELECT CASE SGN(VALUE#)                 ' Evaluate sign of random number
     CASE -1: Desc$ = "negative"
     CASE 0: Desc$ = "zero"
     CASE 1: Desc$ = "positive"
 END SELECT
 mess$ = "The format expression determines how a number is displayed."
 mess$ = mess$ + "In this" + newline$ + "demonstration a random number"
 mess$ = mess$ + " between +2000 and -2000 is generated and"
 mess$ = mess$ + newline$ + "formatted. The number to be formatted is "
 mess$ = mess$ + Desc$ + "." + " Using the format" + newline$
 mess$ = mess$ + "expression provided, the number is displayed as: "
 mess$ = mess$ + FORMAT$(VALUE#, "#,##0.00;(#,##0.00)")
 MSGBOX (mess$)                          ' Display numeric formatting