13.07.2015 Views

Turbo Basic

Turbo Basic

Turbo Basic

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Function TypesFunctions can return any of the four numeric types (integer, long integer, singleand double precision floating point), as well as string types. A function's type, like avariable's, is controlled by its name. It uses type declaration characters and theDEFtype statement; for example:DEF FNIntSquareRoot%(x) = INT(SQR(x»PRINT FNIntSquareRoot%(2)andDEF FNRepeatFirst$(a$) = LEFT$(a$,l) + a$PRINT FNRepeatFirst$("Hello")Attempting to assign a string function to a numeric variable or a numeric functionto a string variable produces what you'd expect-error 13, Type Mismatch.ProceduresProcedures are code blocks surrounded by the SUB and END SUB statements.The fonnal syntax for declaring a procedure isSUB procname [(parameter 7ist)] [INLINE][variab7e dec7aration]• statements[EXIT SUB]END SUBprocname declares the procedure name, which can be up to 31 characters longbut whose name cannot be contained within any other SUB statement in the program.parameter list is an optional comma-delimited list of formal parameters thatrepresent variables to be passed to the procedure when it is called. (You are limitedto 16 parameters for any procedure.) INLINE specifies that the procedure has avariable number of untyped parameters and that the procedure will contain inlineassembly code (see Appendix C, "Assembly Language Interface").As stated earlier, the most obvious difference between functions and proceduresis that procedures don't return a value; however, they also are not called fromwithin expressions, don't have a type, and don't include an assignment to the procedurename. Procedures are invoked with the CALL statement, much likeGOSUB invokes subroutines.86 <strong>Turbo</strong> <strong>Basic</strong> Owner's Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!