Jump to content

Application Development with Harbour/Programming with Functions

From Wikibooks, open books for an open world

A harbour function looks like this.


FUNCTION calculateSum(a,b)
LOCAL sum := a + b
RETURN sum

If you want to use above function calculateSum() you can simply do for example:
sumTwoNumbers := calculateSum(2,4) //The value 6 is saved in sumTwoNumbers
? sumTwoNumbers //prints the value of sumTwoNumbers

Step by step instructions to produce above result:
-Create a file called SumTwoNumbers.prg in directory C:\hb30\tests and open this file.
-Put the following code in this file:

******************SumTwoNumbers.prg
PROCEDURE Main()
Local sumTwoNumbers := calculateSum(2,4)
? sumTwoNumbers
RETURN

FUNCTION calculateSum(a,b)
LOCAL sum := a + b
RETURN sum
*****************

-C:\hb30\bin\hbmk2.exe SumTwoNumbers.prg
-SumTwoNumbers.exe //if right you see number "6"