bas7ex.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.
DATA, DATE$ and READ Programming Example
                       Example                 Contents  Index  Back
──────────────────────────────────────────────────────────────────────────────
'The following example displays the current date by converting the date
'returned by the DATE$ function. The names of months are stored in DATA
'statements and assigned to a string variable using the READ statement.
 
'Get the date.
C$ = DATE$
'Use VAL to find the month from the string returned by DATE$.
FOR I% = 1 TO VAL(C$)
    READ Month$
NEXT
DATA January, February, March, April, May, June, July
DATA August, September, October, November, December
 
'Get the day.
Day$ = MID$(C$, 4, 2)
IF LEFT$(Day$, 1) = "0" THEN Day$ = RIGHT$(Day$, 1)
'Get the year.
Year$ = RIGHT$(C$, 4)
 
PRINT "Today is "; Month$; " "; Day$; ", "; Year$
 
'Sample Output
'
'Today is September 21, 1989
 
 
'This example shows how null data items are handled:
 
RESTORE NullData
 
NullData:
DATA abc,,def
DATA 1,,2
 
READ A$, B$, C$         'B$ = ""
PRINT A$, B$, C$
PRINT
READ A, B, C            'B = 0
PRINT A, B, C
 
'Sample Output
'
'abc                     def
' 1           0           2