Fast Track 2.4: Difference between revisions

From BR Wiki
Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
====Functions====
====Functions====
User defined functions can do anything you want them to do. They must start with the letters FN but contain custom code. Variables can be passed in and out of functions. If something calls a function that starts with FN, then you can find the definition of that function by listing for it.
User defined functions can do anything you want them to do. They must start with the letters FN but contain custom code. Variables can be passed in and out of functions. If something calls a function that starts with FN, then you can find the definition of that function by listing for it.
01100  def fnPrintReport(NextFileKey$;___,PN,Index,ThisVersion)
.... function code
01500  end def
In this example, the user defined function is called fnPrintReport, and the above variables are passed into it. NextFileKey$ is required, but variables following the semi-colon are optional and will be set to null if not passed in.


====LIBRARIES====
====LIBRARIES====
Line 8: Line 14:


Helpful tutorials for both FileIO and ScreenIO are available at [http://www.sageax.com SageAX's] website.  
Helpful tutorials for both FileIO and ScreenIO are available at [http://www.sageax.com SageAX's] website.  
To create a library out of the example above, simply change the DEF line to this:
01100  def LIbrary fnPrintReport(NextFileKey$;___,PN,Index,ThisVersion)
To access it from another program, use a line like this (PrReport is the name of the program the library function is found):
05000 LIBRARY "PrReport": fnPrintReport
05010 LET fnPrintReport(CurFile$)
The LET statement will run the function, passing in the variable CurFile$ to be used in the function as NextFileKey$.


<noinclude>
<noinclude>
[[Category:Fast Track Tutorial]]
[[Category:Fast Track Tutorial]]
</noinclude>
</noinclude>

Latest revision as of 19:10, 10 September 2014

Functions

User defined functions can do anything you want them to do. They must start with the letters FN but contain custom code. Variables can be passed in and out of functions. If something calls a function that starts with FN, then you can find the definition of that function by listing for it.

01100  def fnPrintReport(NextFileKey$;___,PN,Index,ThisVersion)
.... function code
01500  end def

In this example, the user defined function is called fnPrintReport, and the above variables are passed into it. NextFileKey$ is required, but variables following the semi-colon are optional and will be set to null if not passed in.

LIBRARIES

To remove some of the repetitiveness of coding. BR allows you to place code in functions in certain programs, which become libraries, to be used from other programs. Fileio is an example of this. It provides functions for opening, reading, writing and rewriting data by calling library functions and passing variables through them. Complete FileIO documentation is available on the wiki and from SageAX. Or you can create your own functions and libraries.

ScreenIO is another library that allows you to create programs much faster and more efficiently. It is so sophisticated that it can be considered an expression engine, similar to VB.NET.

Helpful tutorials for both FileIO and ScreenIO are available at SageAX's website.

To create a library out of the example above, simply change the DEF line to this:

01100  def LIbrary fnPrintReport(NextFileKey$;___,PN,Index,ThisVersion)

To access it from another program, use a line like this (PrReport is the name of the program the library function is found):

05000 LIBRARY "PrReport": fnPrintReport
05010 LET fnPrintReport(CurFile$)

The LET statement will run the function, passing in the variable CurFile$ to be used in the function as NextFileKey$.