User manual
mikroBasic PRO for PIC32
MikroElektronika
199
Example
Here’s an example procedure which transforms its input time parameters, preparing them for output on Lcd:
sub procedure time_prep(dim byref sec, min, hr as byte)
sec = ((sec and $F0) >> 4)*10 + (sec and $0F)
min = ((min and $F0) >> 4)*10 + (min and $0F)
hr = ((hr and $F0) >> 4)*10 + (hr and $0F)
end sub
A function can return a complex type. Follow the example bellow to learn how to declare and use a function which
returns a complex type.
Example:
This example shows how to declare a function which returns a complex type.
program Example
structure TCircle ‘ Structure
dim CenterX, CenterY as word
dim Radius as byte
end structure
dim MyCircle as TCircle ‘ Global variable
sub function DeneCircle(dim x, y as word, dim r as byte) as TCircle ‘ DeneCircle
function returns a Structure
result.CenterX = x
result.CenterY = y
result.Radius = r
end sub
main:
MyCircle = DeneCircle(100, 200, 30) ‘ Get a Structure via function call
MyCircle.CenterX = DeneCircle(100, 200, 30).CenterX + 20 ‘ Access a Structure eld
via function call
‘ |------------------------| |-----|
‘ | |
‘ Function returns TCircle Access to one eld of TCircle
end.
Forward declaration
A function can be declared without having it followed by it’s implementation, by having it followed by the forward
procedure. The effective implementation of that function must follow later in the module. The function can be used after
a forward declaration as if it had been implemented already. The following is an example of a forward declaration: