GLBasic User Manual

Main sections

ENDFUNCTION

ENDFUNCTION



The ENDFUNCTION command terminates a FUNCTION code block.

Sample:
 
// Function

// Sample shows the usage of the commands
// FUNCTION / ENDFUNCTION / EXIT
// Due to the complicated syntax of a function
// the command 'New Function' should be used
// from the 'Project' menu to create a function.
GLOBAL a
LOCAL a

Title() // Title line

a$=Right$("123456", 2); // 56
PRINT a$, 100, 80

a=7; b=12; GLOBAL a=15
c=Maximum(a, b) // 7, 12
Center("c="+c, 100) // 12
Center ("a="+a, 140) // 7
Center("b="+b, 180) // 12
Center("GLOBAL a="+GLOBAL a, 220) // 0 (function: Max)
SHOWSCREEN
MOUSEWAIT

// ------------------------------------------------------------- //
// -=# MAX - größere Zahl(a, b) / bigger number(a, b) #=-
// ------------------------------------------------------------- //
FUNCTION Maximum: a, b
// These variables are defined LOCAL:
// a, b
LOCAL ret
IF a>b
ret=a
ELSE
ret=b
ENDIF
// This has no influence on the global variables
a=0
// This will
GLOBAL a=0
RETURN ret
ENDFUNCTION // MAX


// ------------------------------------------------------------- //
// -=# CENTER - Center text #=-
// ------------------------------------------------------------- //
FUNCTION Center: text$, y
// Diese Variablen sind als LOCAL definiert:
// There variables are defined LOCAL:
// text$, y
PRINT text$, (640-LEN(text$)*16)/2, y
ENDFUNCTION // CENTER


// ------------------------------------------------------------- //
// -=# TITLE #=-
// ------------------------------------------------------------- //
FUNCTION Title:
// There variables are defined LOCAL:
// retval
Center("Yippie", 50) // Function call within a function
RETURN // Exit the function
PRINT "Boo hoo", 100, 100 // Never happens
ENDFUNCTION // NAME


// A Function with a string as a return value
// ------------------------------------------------------------- //
// -=# RIGHT$ #=-
// ------------------------------------------------------------- //
FUNCTION Right$: word$, size
// These values are defined LOCAL:
// word$, size
RETURN MID$(word$, LEN(word$)-size, size)
ENDFUNCTION// RIGHT$


Output:
56
Yippie
c=12
a=7
b=12
GLOBAL a=0

See also...