Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

6.4.13 ENCODE$(num_expr, num_int)

The ENCODE$ function returns a string containing a number converted to the base specified. num_expr is the value to convert. num_int is the base to convert. For instance, '2' indicates binary, etc. See also Section 6.9.1, DECODE(str_expr, int_expr)

Example 6-68 ENCODE$ Function

  do
    input 'Enter a number to convert to hex': decnum 
    if  decnum = 0 or _exit  then exit do
    print 'Hex for'; decnum;' is '; encode$(decnum,16) 
  loop
  end
  
  
Enter a number to convert to hex? 34.56 
Hex for 34.56 is 22 
Enter a number to convert to hex? 255 
Hex for 255 is FF 

6.4.14 FORMAT$(expr, str_expr)

Given an expression and a format, FORMAT$ returns the result of the expression in the format indicated.

The '@' format character causes the character not to be translated by the formatter. The '<' and '>' are treated like an '@' character. You can justify a character string, but avoid zero suppression and zero insertion.

The FORMAT$ function takes an expression of any data type for the data to format (the first argument), including string expressions.

Example 6-69 FORMAT$ Function

  z$ = format$('5551234567', '(###)###~-####') 
  print 'Phone number: '; z$ 
  end
 
 
Phone number: (555)123-4567 

The FORMAT$ function returns all asterisks "*" in the case of overflow.

Example 6-70 FORMAT$ Function - Overflow

  z$ = format$(12.23,'#.##') 
  print z$ 
  end
 
 
**** 

FORMAT$() returns the same string data as given by the following:


        PRINT USING str_expr: expr 

The FORMAT$ function supports the DATE format and date arguments. Given a date in YYMMDD or CCYYMMDD format, FORMAT$ returns the date in the date format requested.


        FORMAT$(z$, '{DATE [argument]}?') 

The ? can be replaced with a mask. If no date argument is provided, the default is MDCY.

Example 6-71 DATE Format with FORMAT$

  z1$ = format$('990122', '{date mdcy}?') 
  z2$ = format$('990122', '{date mdcy}##/##/####') 
  z3$ = format$('20000122', '{date mdcy}?') 
  z4$ = format$('20000122', '{date mdcy}##/##/####') 
  print z1$, z2$ 
  print z3$, z4$ 
  end
 
 
01221999            01/22/1999 
01222000            01/22/2000 

Table 6-7 FORMAT$ Function - Date Arguments
DATE
Argument
YYMMDD
Input
Result CCYYMMDD
Input
Result
none 991213 12131999 20201213 12132020
YMD 991213 991213 20201213 201213
CYMD 991213 19991213 20201213 20201213
MDY 991213 121399 20201213 121320
MDCY 991213 12131999 20201213 12132020
DMY 991213 131299 20201213 131220
DMCY 9911213 13121999 20201213 13122020
DMONY 991213 13-Dec-99 20201213 13-Dec-20
DMONCY 991213 13-Dec-1999 20201213 13-Dec-2020
MONTHDY 991213 December 13, 99 20201213 December 13, 20
MONTHDCY 991213 December 13, 1999 20201213 December 13, 2020

The FORMAT$ function supports character rotation. The ROTATE option rotates the last nn characters of a string to the first position in the string.


        FORMAT$(z$, '{ROTATE n}?') 

The ? can be replaced with a mask.

6.4.15 GEODISTANCE(str_expr1, str_expr2)

The GEODISTANCE function calculates the "crow flies" distance in miles between any two points. str_expr1 and str_expr1 contain comma separated latitude and longitude coordinates. The distance in miles is rounded to three decimal points.

If invalid or blank parameters are entered for the latitude and longitude, instead of an exception a value of 99999 is returned.

Example 6-72 GEODISTANCE Function

  here$  = '37.423021,-122.083739' 
  there$ = '42.730287,-73.692511' 
 
  miles = geodistance (here$, there$) 
  print 'Distance is: '; miles; 'miles' 
 
 
Distance is:  2555.453 miles 

6.4.16 GETSYMBOL$(str_expr1,[boolean])

The GETSYMBOL$ function is used to return script variables and symbols. These can be the results of an HTML form submission, CGI environment variables, Sheerpower symbols, DNS symbols, operating system symbols, or any variable you have defined as a symbol.

The GETSYMBOL$ function has an optional parameter that allows you to not trim the leading and trailing spaces of a symbol returned. The default parameter is set to TRUE. "True" is implied and means that the leading and trailing spaces will be trimmed. The FALSE parameter can be used if you do not want the leading and trailing spaces trimmed from the symbol retrieved.

Example 6-73 GETSYMBOL$ Function: Sheerpower Symbol & Trimming Option

  set system, symbol 'test': value '  hi there' 
  print '<';getsymbol$('sp:test');'>'
  print '<';getsymbol$('sp:test', false);'>'
  print '<';getsymbol$('sp:test', true);'>'
  
<hi there> 
<  hi there> 
<hi there>  

Below are a few more examples of GETSYMBOL$:

Example 6-74 GETSYMBOL$ Function: HTML form submission

  //  print the contents of the symbol "city" from a HTML form submit. 
  print getsymbol$('city') 

Example 6-75 GETSYMBOL$ Function: CGI Environment Symbol

  // print the contents of the environment symbol REMOTE_ADDR 
  print getsymbol$('env:REMOTE_ADDR') 

Example 6-76 GETSYMBOL$ Function: Operating System Symbol

  // print the contents of the operating system symbol PATH 
  print getsymbol$('os:PATH') 
  // and list the contents of the TEMP directory 
  print getsymbol$('os:TEMP') 
 
 
C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\PROGRA~1\Java\JRE16~2.0_0\bin;C:\WINDOWS\sys 
tem32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\PROGRA~1\ABSOLU~1;C:\Program Files\
QuickTime\QTSystem\;C:\Program Files\IDM Computer Solutions\UltraEdit\;C:\Progra 
m Files\IDM Computer Solutions\UltraCompare;. 
C:\DOCUME~1\User\LOCALS~1\Temp 

Below is a list of symbol prefixes supported:

Table 6-8 Supported Symbol Prefixes
Symbol Prefix Description
env: CGI environment variables (see Section 18.3.8, Summary of CGI Environment Variables)
os: Operating system symbols. If the symbol begins with a \ then it is a registry symbol.
sp: Sheerpower symbols (see Section 11.15.17, SET SYSTEM, SYMBOL: VALUE )
dns: DNS symbols (see Section 11.15.16, Performing DNS Lookups with ASK SYSTEM, SYMBOL )

6.4.17 GETWORD$(str_expr1 [, num_expr [, str_expr2]])

The GETWORD$() function returns a given word from str_expr1 which is specified by the num_expr. By default, words contain A-Z, a-z, 0-9. The default can overridden with an optional 3rd parameter str_expr2 that specifies what characters define a word.

Example 6-77 GETWORD$ Function

  addr$ = 'N 123rd Baker Street Apt 200' 
  print getword$(addr$, 2) 
  end     
 
 
123rd 


Previous Next Contents Index