| Previous | Contents | Index |
Given a full-time string in CCYYMMDD HHMMSS, YYMMDD HHMMSS, HHMMSS or HHMM format, the SECONDS function returns the number of seconds since the SheerPower base date (January 1, 1600 00:00:00).
The number of seconds is returned as a floating point number.
| Example 6-44 SECONDS function |
|---|
z = seconds('20000122 103050')
z1 = seconds('990122 103050')
z2 = seconds('103050')
z3 = seconds('1030')
print 'Seconds cymdhms ='; z
print 'Seconds ymdhms ='; z1
print 'Seconds hms ='; z2
print 'Seconds hm ='; z3
end
Seconds cymdhms = 12624633050
seconds ymdhms = 12593097050
seconds hms = 37850
seconds hm = 37800
|
The value returned by the TIME function depends on the value of int_expr.
If int_expr = 0, TIME returns the number of seconds since midnight.
If int_expr = 1, TIME returns the CPU time of the process in tenths of a second.
If int_expr = 2, TIME returns connect time of the current process in minutes.
| Example 6-45 TIME function |
|---|
print time(0) print time(1) print time(2) end 67004 1 0 |
TIME(5) returns the number of seconds since SheerPower was invoked. This function can be used to time events to the nearest 100th/sec.
| Example 6-46 TIME(5) function |
|---|
print time(5) .03 |
or
If num_expr is NOT specified, TIME$ returns the current time of day in HH:MM:SS format.
num_expr is the number of seconds since midnight. The result is returned in HH:MM format.
| Example 6-47 TIME$ function |
|---|
print time$(1800) print time$(54178) print time$ end 00:30 15:02 11:33:27 |
Many applications allow the end-user to enter a six-digit date. For a six-digit date, SheerPower 4GL needs to know if the YEAR is in the 19th century or the 20th century. For example:
161231 |
Is this 1916, December 31st or is this 2016, December 31st?
By default, SheerPower assumes that if a six-digit date is given, and the YEAR is less than 20, then this is the 20th century. In the example above,:
161231 --> December 31, 2016 |
The default PIVOT DATE is year 20.
The default pivot date can be changed by creating a logical:
SheerPower_Y2K_PIVOT |
This can be done with the following small program:
| Example 6-48 Pivot Date Logical |
|---|
set system, logical 'SheerPower_Y2K_PIVOT': value '17' |
You can add the following to the c:\sheerpower\sp4gl_YOURNAME.ini file:
[logicals] SheerPower_Y2K_PIVOT=17 |
Then the value will automatically be setup for all SheerPower applications. The logical is checked for only ONCE at sp4gl.exe STARTUP time.
The following are string manipulation functions that SheerPower performs:
The ASCII function returns the decimal ASCII value of a string's first character. It is returned as an integer. The Section 6.4.4 is the opposite of the ASCII function.
| Example 6-49 ASCII function |
|---|
print ascii('A')
65
|
CHANGE$ changes specified characters in str_expr1. str_expr1 is the source string. str_expr2 contains the target characters, and str_expr3 specifies the substitution characters. CHANGE$ returns the changed string.
CHANGE$ searches for the target characters within the source string and replaces these characters with the substitution characters. The substitution characters are mapped onto the target characters.
| Example 6-50 CHANGE$ function |
|---|
let a$ = 'bdbdbdbd' let b$ = 'b' let c$ = 'c' let changed$ = change$(a$, b$, c$) print a$ print changed$ end bdbdbdbd cdcdcdcd |
CHARSET$ returns the character set specified. The optional string expression can be used to specify the character set to return. The available character sets are:
| UCASE | all upper-case letters (A-Z) | |
| LCASE | all lower-case letters (a-z) | |
| CONTROL | all control characters (ASCII 0-31) | |
| ASCII | the ASCII character set, in order (0-255) |
ASCII is the default character set for CHARSET$.
| Example 6-51 CHARSET$ function |
|---|
line input 'Enter your text': text$
// change upper-case to lower-case
ct$ = change$(text$, &
charset$('ucase'), &
charset$('lcase'))
print 'Lower-case version is:'; ct$
end
Enter your text? TESTER
Lower-case version is: tester
|
CHR$ returns a string with the specified ASCII value (int_expr1) repeated the specified number of times (int_expr2). If no count is specified, a default count of one is used.
| Example 6-52 CHR$ function |
|---|
x = 65 print chr$(x) // prints A -- the 65th ASCII character end A |
Given an integer (int_expr1) and an optional length (int_expr2), which defaults to four, the CONVERT$ function returns a string mapping of the integer.
If the optional data type (int_expr3) is 17, the returned string will be a packed floating (PF).
The following data types are supported:
| Data Type | Conversion Result |
|---|---|
| 1 | Integer (2 or 4 byte) |
| 7 | COBOL comp-3 (C3 packed decimal) |
| 17 | Packed floating (PF) |
| Example 6-53 CONVERT$ function - supported data types |
|---|
a$ = convert$(16961)
print a$
end
AB
|
Given a string containing a mapped integer, the CONVERT function returns the integer value.
| Example 6-54 CONVERT function |
|---|
a$ = 'AB' b = convert(a$) print b end 16961 |
The CONVERT and CONVERT$ functions can be used in situations such as building segmented keys consisting of multiple data types.
CPAD$ returns a new string, padded on the left and on the right with pad characters. text_str is the string to be centered, size is the size of the new string. The default pad character is a space.
| Example 6-55 CPAD$ function |
|---|
print cpad$('123', 9, '0')
end
000123000
|
EDIT$ performs one or more editing operations on the supplied string argument, depending on the value of the integer expression. The integer expression is one of the integers below, or a sum of integers below for the desired edit functions:
| Value | Edit Operation |
|---|---|
| 1 | Trim parity bits. |
| 2 | Discard all spaces and tabs. |
| 4 | Discard characters: CR, LF, FF, ESC, RUBOUT and NULL. |
| 8 | Discard leading spaces and tabs. |
| 16 | Reduce spaces and tabs to One space. |
| 32 | Convert lower case to upper case. |
| 64 | Convert "[" to "(" and "]" to ")". |
| 128 | Discard trailing spaces and tabs. |
| 256 | Do not alter characters inside quotes. |
| Example 6-56 EDIT$ function |
|---|
print edit$('hi there, how are you today?' , 32)
HI THERE, HOW ARE YOU TODAY?
|
| Previous | Next | Contents | Index |