Formula Solver 1.4 4/

BBS: Inland Empire Archive
Date: 03-19-93 (21:00)             Number: 371
From: QUINN TYLER JACKSON          Refer#: NONE
To: ALL                           Recvd: NO
Subj: Formula Solver 1.4    4/       Conf: (2) Quik_Bas
>>> Continued from previous message
' Push the parameters to the variable stack temporarily

IF SymPtr < SYMMAX THEN
' Since it wasn't, put it there
VariPtr = VariPtr + 1
SymPtr = SymPtr + 1

IF VariPtr <= VARMAX THEN
SymTable(SymPtr).SymName = Param\$(i%)
SymTable(SymPtr).SymType = SymVARIABLE
SymTable(SymPtr).TabPtr = VariPtr
SymTable(SymPtr).SymLvl = LvlPtr + 1
VarTable(VariPtr) = ParValue(i%)
ELSE
ErrorCode = eqjVariableTableFull
END IF
ELSE
ErrorCode = eqjSymbolTableFull
END IF

NEXT i%

fqjSolveFormula = fqjEvaluate(Formula\$)

VariPtr = VariPtr - Tot%    ' Clear the variable stack of
SymPtr = SymPtr - Tot%      ' variables used in parameter
END FUNCTION

FUNCTION fqjVAL (InText\$)

' Initialize some variables....

IF LvlPtr < MAXLEVELS THEN
LvlPtr = LvlPtr + 1

DIM CommandArray\$(MAXCOMMANDS)

' separate statement by semicolons
CALL sjfParse(CommandArray\$(), InText\$, ";", Tot%)

FOR i% = 1 TO Tot%
fqjVAL = fqjEval(CommandArray\$(i%))

IF ErrorCode THEN
fqjVAL = 0
EXIT FUNCTION
END IF
NEXT i%

LvlPtr = LvlPtr - 1

ELSE
ErrorCode = eqjNestedTooDeep
END IF
END FUNCTION

FUNCTION funSolveEquation (InText\$)

STATIC Initialized%

IF Initialized% = FALSE THEN
RESTORE PredefinedFunctionData
DO
IF N\$ <> "*END*" THEN
CALL sqjAssignFun(N\$, F\$, PROTECTED)
END IF
LOOP UNTIL N\$ = "*END*"

RESTORE SystemVariableData
DO
IF N\$ <> "*END*" THEN
CALL sqjAssignVar(N\$, 0, PROTECTED)
END IF
LOOP UNTIL N\$ = "*END*"

Initialized% = TRUE
END IF

OPERATOR = ADDSUB + MULTDIV + POWER + LOGICAL
WHITESPACE = " " + CHR\$(13) + CHR\$(9) + CHR\$(10)

ErrorCode = 0
WarningCode = 0
LvlPtr = 0
funSolveEquation = fqjEvaluate(InText\$)

END FUNCTION

SUB sjfParse (Word\$(), Txt\$, Spt\$, WordNum%)

Text\$ = Txt\$
WordNum% = 0
SepLen% = LEN(Spt\$)

DO
WordNum% = WordNum% + 1
EndWord% = INSTR(Text\$, Spt\$)
IF EndWord% THEN
Word\$(WordNum%) = LEFT\$(Text\$, EndWord% - 1)
Text\$ = MID\$(Text\$, EndWord% + SepLen%)
ELSE
Word\$(WordNum%) = Text\$
Text\$ = ""
END IF
LOOP WHILE LEN(Text\$)
END SUB

SUB sqjApplyOp (Op\$, x, y)

' This is the meat of the operator section, and can be modified to
' includ ANY symbol as an operator, or any two byte symbol combination.
' Any symbol added has to be added to the constant that sets its
' level of precedence.

SELECT CASE Op\$
CASE "-"    ' subtraction
x = x - y
x = x + y
CASE "*"    ' multiplication
x = x * y
CASE "/"    ' division
IF y <> 0 THEN
x = x / y
ELSE
ErrorCode = eqjDivisionByZero
END IF
CASE "\"    ' integer division
IF y <> 0 THEN
x = x \ y
ELSE
ErrorCode = eqjDivisionByZero
END IF
CASE "%"    ' modulo division
IF y <> 0 THEN
x = x MOD y
ELSE
ErrorCode = eqjDivisionByZero
END IF
CASE "^", "**"  ' exponentation
x = x ^ y
CASE "}"    ' the rth root of y
IF y <> 0 THEN
x = y ^ (1 / x)
>>> Continued to next message

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