Functions are very similar to subs with exception that functions return values back to the part of the program that called the function. Functions receive values passed by the section of the program that called the function. The functions take the values passed to it, performs a calculation or computation and returns a value.
By this point you have already used functions many times. UCASE$ is a function that converts text to uppercase. UCASE$ takes a string, converts the string to uppercase and returns the uppercase string value. Other built-in functions include ABS, LOG, and INKEY$.
Creating a function is very similar to creating a sub. All that is needed to create a function is to click Edit --> New Function, then, in the dialog box, type the name of the new function and click OK.
To view functions, click View --> Subs and the dialog box appears with all the subs and functions to choose from. It might have been best if Microsoft named the menu “View” --> “Sub and Functions”.
Code Download
QBT38_1.BAS
QBT38_2.BAS
QBT38_3.BAS
QB64 is a free download at www.qb64.com
QB64 Wiki & Manual is found at qb64.com/wiki.html
QBasic 1.1 comes with OldDOS. A zip file of OldDOS can be found at www.pcxt-micro.com/download.html
QBasic 1.1 needs DOSBox to run on Windows Vista and greater, Mac, and Linux.
DosBox is a free download at www.dosbox.com
Free QB64/QBasic Code
QBasic.Net - www.qbasic.net
Pete's QBasic Site - www.petesqbsite.com/index.php
QB45 - qb45.org
Phatcode - games.phatcode.net