| Previous | Contents | Index |
all_of_file$ = fileinfo$('some_file.xxx', 'contents')
|
| Example 6-156 FILEINFO$ function - CONTENTS |
|---|
all_of_file$ = fileinfo$('sheerpower:sheerpower.ini', 'contents')
print all_of_file$
end
! the specified file contents will display in the console window when the program
! is run:
[license]
LicenseKey=F0CE-2E43-7583-3130-3030-3030-3131-0003-873F-000A
Username=non-commercial
EmailAddress=non-commercial
|
| Example 6-157 Copy a file with FILEINFO$ CONTENTS |
|---|
sourcefile$ = 'source.xxx' destfile$ = 'destination.xxx' contents$ = fileinfo$(sourcefile$, 'contents') open file dest_ch: name destfile$, access output, unformatted print #dest_ch: contents$ close #x end |
Given a file name to find, FINDFILE$ returns the complete file specification of the first file found that matches the name given. If no file is found, the function returns a null string.
FINDFILE$ calls can be nested if the inner call has only one argument (i.e., the file specification, but no index number).
| str_expr | The name of the file to search for. This can be just part of the full file specification. | |
| int_expr | Which file specification to return if multiple files are found. This parameter is optional. The default is to return the first file found. | |
| result | The complete file specification of the file found. |
| Example 6-158 FINDFILE$ function |
|---|
print findfile$('sheerpower:\samples\*.spsrc')
c:\sheerpower\samples\cdplayer.spsrc
|
| Example 6-159 FINDFILE$ function |
|---|
do
line input 'File specification': spec$
if _exit then exit do
for i = 1 to 9999
file$ = findfile$(spec$, i)
if file$ = '' then exit for
print file$
next i
loop
end
File specification? sheerpower:samples\client.* <---- type this in
c:\sheerpower\samples\client.ars
c:\sheerpower\samples\client.def
c:\sheerpower\samples\client.fdl
c:\sheerpower\samples\client.str
File specification? exit
|
The following are debugging and exception handling functions that SheerPower performs:
_DEBUG returns a TRUE or FALSE value. TRUE if DEBUG is on. FALSE if DEBUG is off.
| Example 6-160 _DEBUG system function |
|---|
debug on
if _debug then
print 'I am debugging'
end if
debug off
if _debug then
print 'I am still debugging.'
else print 'I am no longer debugging.'
end if
end
I am debugging.
I am no longer debugging.
|
_STATUS returns the value given to SheerPower by the operating system for the last operating system request. It also returns the operating exception number for the last exception that occurred. This function is useful when debugging system level errors. The _STATUS function is often used with the SYSTEXT$ function.
| Example 6-161 _STATUS system function |
|---|
when exception in
open #1: name 'c:\stuff\otherstuff\myfile.txt'
close #1
use
print 'The error was: '; systext$(_status)
end when
end
The error was: The system cannot find the path specified.
|
Upon the completion of an INPUT MENU statement, the concept _STRING contains the menu path taken by the user when selecting the menu item. (i.e., "#2;#3" means the 3rd item of the 2nd submenu.)
| Example 6-162 _STRING system function |
|---|
line1$ = '%width 12, %menubar, %autovbar ON,'
line2$ = 'file = {new, get_file, save, save_as},'
line3$ = 'edit = {cut, copy, paste},'
line4$ = 'paragraph = {font, alignment, spacing, tabs, headers, footers},'
line5$ = 'options = {ruler = {on, off}, side_bar = {on, off},'
line6$ = 'view = {enlarged, normal, small}},exit'
test_menu$ = line1$ + line2$ + line3$ + line4$ + line5$ + line6$
the_default$ = ''
do
input menu test_menu$, default the_default$: ans$
if _exit then exit do
message 'Menu path was', _string
the_default$ = _string
loop
end
+------------------------------------------------------------------------------+
| FILE | EDIT | PARAGRAPH | OPTIONS | EXIT |
+--------------------------------------------+---OPTIONS---+-------------------+
| RULER [>|
| SIDE_BAR +----VIEW-----+
| VIEW | ENLARGED |
+-----------| NORMAL |
| SMALL |
+-------------+
The menu path was: #4;#3;#2
|
EXLABEL$ returns the routine name and line number executing when the last exception occurred, e.g., DO_INPUT.4
| Example 6-163 EXLABEL$ function |
|---|
try_it
stop
routine try_it
when exception in
open #1: name 'xx.yy'
use
print 'Open error at '; exlabel$
print 'Error was: '; extext$(extype)
end when
end routine
Open error at TRY_IT.0002
Error was: File not found
|
EXTEXT$ returns explanatory text associated with a specified exception number. See also the EXLABEL$ function example above.
| Example 6-164 EXTEXT$ function |
|---|
print extext$(2001) Subscript out of bounds |
EXTYPE returns the number of the last exception that occurred. It is returned as an integer.
| Example 6-165 EXTYPE function |
|---|
try_it
stop
routine try_it
when exception in
open #1: name 'xx.yy'
use
print 'Open error at '; exlabel$
print 'Error was: '; extype
end when
end routine
Open error at TRY_IT.0002
Error was: 7110
|
or
SYSTEXT$ returns the text associated with the operating system status specified. If no int_expr is supplied, SheerPower returns the text for the last system status. SYSTEXT$ is often used with _STATUS system function.
| Example 6-166 SYSTEXT$ function |
|---|
print systext$ The operation completed successfully. |
The following are miscellaneous functions that SheerPower performs:
With the DECODE function, given the string representation of a number and the base that the value is in (int_expr), SheerPower returns the value in base 10. The number is returned as a real number. See also Section 6.4.11, ENCODE$(num_expr, num_int).
| Example 6-167 DECODE function |
|---|
do
line input 'Enter a HEX value', default 'ff': hex$
if _exit then exit do
print 'Decimal value is'; decode(hex$,16)
loop
end
Enter a HEX value? ff
Decimal value is 255
Enter a HEX value? exit
|
| Previous | Next | Contents | Index |