FUNC ENDFUNC |
[Features] To define user
function.
[Format] FUNC
funcname[$](variable[$][,variable[$]]...) :ENDFUNC [retvalue]
[Explanation]
To define User function.
The function name and variables used are
specified.
When dealing with string
return value, '$' is put to func-name end. (cf. line 130)
The arguments been placement into
brackets according to the number.
If
the argument is in string type, '$' is put to the variable-name end.
It return to original position by
'ENDFUNC'.
Return value is written
behind 'ENDFUNC'. (if omit return 0 or Null-string)
It is called in this form. [
a=fname(var1,var2) ]
The variable
which appeared by the inner side of the function is defined as local
variable.
Even if the original global
variable is used with local scope, it is still global.
The function definition can be placement
anywhere.
[e.g.]
[smp_func.bas]
10 d=4
20 f=pow(8,d)
30 print f
40
st$=initial$("android")
50 print st$
100 func pow(a,b)
110 c=a^b
120 endfunc c
130 func
initial$(s$)
140 if len(s$)>0 then
r$=left$(s$,1)
150 endfunc r$
' This case
' Global d, (f, st$ :This variable of call, it
define after returning from the function)
'
Local a, b, c, s$, r$
(Result)
4096
a
[Supplement]
The
notes of the global variable definition position.
10 f=ts()
20d1=0:d2=0
30 func ts()
40d1=1:d2=2
50 print d1;d2
60 endfunc
Although the variables d1,d2 are in the
position of global variable in this example,
When the user function is called for
instruction execution time by line[10],
it doesn't define automatically
yet.
So it becomes treatment of local
variable when it appeared in [line40].
Because the variable'f'[line10]
which receive return-value is also in the state
which isn't defined at the time of
ts()-function call.
(It is defined
when be back and timing substituted)
The global variable used with user
function,
please be sure to
define beforehand as global variable
before it is called function[line10] and it is defined
function[line30],
Like below
example.
10d1=0:d2=0:f=0
20 f=ts()
30 func ts()
40d1=1:d2=2
50 print d1;d2
60 endfunc
SELECT CASE END SELECT |
[Features] According to the
value of a formula, execution moves to an applied command group.
[Format] SELECT
CASE expression:
CASE a: END SELECT
[Explanation]
To
execution one of several groups of statements, depending on the value of
'expression'.
'case else' is selected
when applied to nothing.
The data
treated by 'expression' also support string variable & constant.
[e.g.] [smp_select.bas]
10 input dat
20 select case dat
30 case 1:
40 color col(15)
50 print "First"
60 case 2:
70 color col(7)
80 print "second"
90 case else:
100 color col(2)
110 print "Other"
120 end select