BBS: Inland Empire Archive Date: 03-19-93 (21:58) Number: 375 From: QUINN TYLER JACKSON Refer#: NONE To: ALL Recvd: NO Subj: About Formula Solver Conf: (2) Quik_Bas

The previous seven part post is the revised version of my formula solver. New to this version are definable functions and some bug fixes to version 1.0. I've numbered this 1.4 because there were 3 intermediate versions at my end before reaching this one. This message is to serve as a brief tutorial on the syntax of theFUNCTIONfunSolveEquation(InText$). First of all, there are standard statements: 1+1 2+3 9*2+2 etc. That's fairly simple. Then, there are more advanced operators, such as ` and # and }. -4` = 4 That is to say, ` returns the ABSOLUTE value of x. 4.5# = 4 That is to say, # returns the integer part of x. 2}4 means "the square root of 4" 3}8 means "the cube root of 4" That is, n}x returns the nth root of x. Then, there are exotic operators, such as !, which is the factorial symbol, which means that 5! returns 5 factorial, or 1x2x3x4x5, or 120. 0! is 1 by definition. There are other operators: 5%2 works as 5MOD2 5\2 does integer division 5~7 works as 5XOR7 5&7 works as 5AND7 5|7 works as 5OR7 Some logical operators: 1>2 returns 0, for false 1<>2 returns -1, for true 5==2 returns 0, for false (1<3)|=(2==1) returns -1, for IMPLIED TRUTH Parenthesis override standard BODMAS precedence. Therefore: 5*(1+2) returns 15, rather than 7. VARIABLE ASSIGNMENT: Variables are case insensitive, and can consist of: first character must be either @ or A-Z subsequent characters can be anything but spaces or operators (numbers or commas are legal, as are underscores, but A^TEST would be a to the power of test. Variable assignment is achieved by the statment: Variable:=equation Therefore, one could do any of the following: STATEMENT VALUE OF A ___--------------------------------------------- A:=10 10 A:=10*2 20 A:=square_root[9] 3 Suppose A is equal to 10, the following would change its value to 20: A:=A*2 FUNCTIONS: Functions are assigned in a similar fashion to variables. square[x]:=x^2 Now, whenever a value for the x parameter is supplied, it is put into the formula, and the function returns the result. Variables in function parameters are local to those functions and are dynamic. That is to say, if x is specified as being 100 somewhere else, that doesn't affect the function. Therefore, square[10] would return 100. square[n] would return 4 if n were equal to 2 square[1+5] would return 36 and square[square[2]] would return 16, and is an example of the nesting that is possible with functions. In the definition of the function, one can assign parameter defaults. That is, one can supply values for the parameters that are used as a default value if that parameter is not supplied in the call. area[radius,pi:(22/7)]:=pi*radius^2 As it stands, suppose someone were to then call the function like this: area[10] This would return 31.429, using the default of 22/7 for pi, which is a rough approximation. However, if a stickler were to come along and demand a more accurate value for pi, he could supply the missing parameter: area[10,3.14159] and the function would use this value for pi rather than the default. Note that when the default parameter is at theENDof the paremeter list in the function definition, there is no need for a placeholder. In other locations, one is required: area[pi:22/7,radius]:=pi*radius^2 Now, to call this using the default value for pi, one would have to do this: area[,10] The , serves as a place holder for the missing parameter, just as in the BASIC statement:LOCATE,10 SOME ADVANCED TOPICS: Multiline statements are possible. The result of the LAST calculation in the list is what funSolveEquation returns. Therefore, one could do this: 2 a:=1;b:=2;c:=3;a+b+c This would return the value 6. Functions canNOT take advantage of this feature. I leave you to figure out the rest.... Quinn * OLX 2.1 TD * Programming is never saying you're finished.... --- Maximus/2 2.01wb * Origin: The Nibble's Roost, Richmond BC Canada 604-244-8009 (1:153/918)

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