PowerBASIC
Adding uCalc to your PB application
In order to implement uCalc Fast Math Parser in PowerBASIC (PB/Win or PB/CC), follow these steps:
#INCLUDE
"uCalcPB.Bas"
Now you're all set to go.
Note: PowerBASIC files are found in the ucFMP296\PB\ directory.
Native callbacks
In other supported compilers, the Expr argument for native callbacks is passed as a Long or Dword integer. In PB, it is passed using the ucExpression type, which allows ucParam to be defined as a macro that deals directly with pointers. ucParam as a macro is faster than ucParam as a function.
Demo program
A user-friendly form-based demo is found in a file named DemoPB.Bas. The source code in that file demonstrates the essential features, especially as they relate to PowerBASIC. Because it is form-based, it will compile with PB/Win, and not PB/CC. However, if you only have PB/CC, you can still run the compiled DemoPB.exe file to see how it works.
Examples:
The following examples are for key features that may have some peculiarities in PowerBASIC. The following examples compile with PB/Win. In order to run them in PB/CC, change statements such as MsgBox to Print, and InputBox to Line Input. There are many more examples in Visual Basic that are close enough to PB. Those are listed under More Examples.
Example 1: Simple evaluation with ucEvalStr
Example 2: Fast evaluation millions of times in a loop
Example 3: Defining a centralized error handler
Example 4: Raising an error with ucRaiseErrorMessage
Example 5: A native function callback with two
numeric arguments
Example 6: A native function callback with any
number of arguments
Example 7: A native string callback function
Example 8: A non-native function callback
Example 9: Strings in non-native functions
Example 10: Attached variables
See More Examples
Remarks
ucReturn Expr, a + b ' This line will not
compile
ucReturn(Expr, a + b) '
This line will compile
Also, ucReturnStr is a multi-line macro and should be the only statement in a line. Therefore the following line doesn't compile in PB/Win 8 or PB/CC 4:
If x = 1 Then
ucReturnStr(Expr, "T") Else ucReturnStr(Expr, "F")
Do the following instead:
If x = 1 Then
ucReturnStr(Expr, "T")
Else
ucReturnStr(Expr, "F")
End If
New or enhanced in version 2.96
New or enhanced in version 2.9+