Calling a Function?

 BBS: Inland Empire Archive
Date: 04-22-92 (05:09)             Number: 115
From: BILL BEELER                  Refer#: NONE
  To: ZACK JONES                    Recvd: NO  
Subj: Calling a Function?            Conf: (2) Quik_Bas
In a message to Matt Hart <20 Apr 92 19:20> Zack Jones wrote:

 ZJ> use it in other parts of my program, correct?  Since I have a
 ZJ> better understanding of SUBS - would you please show me how to
 ZJ> change it from a function to a SUB.  Your help is greatly appreciated!

Zack,

A FUNCTION is similar to a SUB in that it will perform some type of work,
variables can be passed to and returned from it. But the
main difference lies in that it will return a value as it's
name. This allows at least two things that are impossible
with a SUB, those being boolean compares and passing at
least one less variable. Maybe the following (lame) code
will help.


'Procedures
SUB GetKey (Ky$)
  Start! = TIMER
  DO
    A$ = INKEY$
  LOOP UNTIL LEN(A$) OR TIMER - Start! > 3
END SUB

FUNCTION GetKy$
  Start! = TIMER
  DO
    A$ = INKEY$
  LOOP UNTIL LEN(A$) OR TIMER - Start! > 3
  A$ = GetKy$
END FUNCTION


'Program
DEFINT A-Z
DECLARE SUB GetKey(Ky$)
DECLARE FUNCTION GetKy$()

GetKey(Ky$)                     'here Ky$ is null
IF LEN(Ky$) THEN PRINT Ky$      'here Ky$ may or may not be null depending on
                                'what is returned thru the variable

Ky$ = GetKy$                    'here Ky$ may or may not be null
IF LEN(Ky$) THEN PRINT Ky$


While it isn't the most elegant or best example it should
give you an idea of the difference between the two. IMO
it's best to use FUNCTIONs where possible.

                                               ...Bill...


--- GEcho/beta
 * Origin: Amber Shadow BBS, Marysville, CA (1:203/988)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET