Category : Batch File Utilities - mostly for DOS
Archive   : BLDR150.ZIP
Filename : CALC.BLD

 
Output of file : CALC.BLD contained in archive : BLDR150.ZIP

'Sample program for Builder 1.50
'A Little Calculator
'By Doug Amaral

'Our Variables at the top of the Program
String Key 'Hold the Key that was pressed
Integer KeyVal 'Hold Value of LastKey
Integer x 'Spacer for Calculator
Integer KeyX, KeyY 'This is the value passed to the Key Toggle Routine
String ToggleStr 'This is the String that is toggled
Integer NextOp 'This Hold a flag for what the next operation is
'to be 1 for +, 2 for -, 3 for *, 4 for /
'5 for AND, 6 for OR, NOT is done immediately
String SVar1 'Holds the current variable in string form
LongInt IVar1 'Holds the current variable in integer form
String SVar2 'Holds the previous integer as a string
Longint IVar2 'Holds the previous integer (either result or entry)
Integer i 'General Purpose Integer
Longint l 'General Purpose LongInt
'Set the variables
'Set column to 20, when TapeOn is true this will be set to 5
x:=20
Don't Use Cursor

'Main Loop

RedrawScreen 'Call to Redraw the screen
:Main
GetKey
If Lastkey == {F1}
HelpScreen
RedrawScreen 'Call to Redraw the screen
goto Main
end
If LastKey == {T}
if x==20 x:=5 else x:=20
'Set the Tape on Flag
TapeOn:=1
'Go act on the key stroke
RedrawScreen
end
If LastKey == {t}
if x==20 x:=5 else x:=20
'Set the Tape on Flag
TapeOn:=1
'Go act on the key stroke
RedrawScreen
end

DoKey
goto Main

'This Routine Displays Top Status Line and the Calculator
Sub RedrawScreen
'Clear the Screen
Cls
'Display
Text Yellow on Blue
Say @ 1,1 "The Little Calculator Program ESC = Exits F1 = Help "
Double Box 10,x,40,10 Blue on Blue
'Display the read out
i:=Length SVar1
i:=18-i+2
Say @ 11,x+2 " "
Say @ 11,x+i ""+Svar1

'Display the first column of keys
Say @ 13,x+2 " 1 "
Say @ 15,x+2 " 4 "
Say @ 17,x+2 " 7 "

'Display the second column of keys
Say @ 13,x+8 " 2 "
Say @ 15,x+8 " 5 "
Say @ 17,x+8 " 8 "

'Display the Third column of keys
Say @ 13,x+14" 3 "
Say @ 15,x+14" 6 "
Say @ 17,x+14" 9 "
Say @ 17,x+20" 0 "

'Display the clear Button
Say @ 11,x+25 " Clear "

'Display Bitwise Operators
Say @ 13,x+20 " AND "
Say @ 13,x+27 " OR "
Say @ 13,x+33 " NOT "

'Display Arithmatic Operators
Say @ 15,x+20 " + "
Say @ 15,x+25 " - "
Say @ 15,x+30 " * "
Say @ 15,x+35 " / "

'Display the Equals Button
Say @ 17,x+30 " = "
End

'This Routine Displays the Help Screen
Sub HelpScreen
Double Box 6,10,60,15 Yellow on Green
Text Blue on Green
Say @ 7,16 " Welcome to the Builder Little Calculator"
Say @ 7+1,16 " Just in case you wanted to know:"
Say @ 7+2,16 " This calculator was written"
Say @ 7+3,16 " 100% in BUILDER 1.50"
Say @ 7+5,16 " Also:"
Say @ 7+6,16 " To add two numbers just enter the number"
Say @ 7+7,16 " the + and then another number. The other"
Say @ 7+8,16 " operators work the same way, except NOT."
Say @ 7+9,16 " NOT effects the active number only"
GetKey
END

'This Routine Acts on the key stroke
Sub DoKey
Select LastKey from
Case {ESC}:
'Exit the stuff
cls
Use Cursor
Exit 0

Case {1}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+2
Keyy:=13
ToggleStr:=" 1 "
ToggleKey
AddNumber
Case {2}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+8
Keyy:=13
ToggleStr:=" 2 "
ToggleKey
AddNumber

Case {3}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+14
Keyy:=13
ToggleStr:=" 3 "
ToggleKey
AddNumber

Case {4}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+2
Keyy:=15
ToggleStr:=" 4 "
ToggleKey
AddNumber

Case {5}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+8
Keyy:=15
ToggleStr:=" 5 "
ToggleKey
AddNumber

Case {6}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+14
Keyy:=15
ToggleStr:=" 6 "
ToggleKey
AddNumber

Case {7}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+2
Keyy:=17
ToggleStr:=" 7 "
ToggleKey
AddNumber

Case {8}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+8
Keyy:=17
ToggleStr:=" 8 "
ToggleKey
AddNumber

Case {9}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+14
Keyy:=17
ToggleStr:=" 9 "
ToggleKey
AddNumber

Case {0}:
'Set the coordinates for Toggle Key
If NextOp==10 SVar1:=""
Keyx:=x+20
Keyy:=17
ToggleStr:=" 0 "
ToggleKey
AddNumber

Case {+}:
'Set the coordinates for Toggle Key
Keyx:=x+20
Keyy:=15
ToggleStr:=" + "
ToggleKey
Evaluate
NextOp:=1

Case {-}:
'Set the coordinates for Toggle Key
Keyx:=x+25
Keyy:=15
ToggleStr:=" - "
ToggleKey
Evaluate
NextOp:=2

Case {*}:
'Set the coordinates for Toggle Key
Keyx:=x+30
Keyy:=15
ToggleStr:=" * "
ToggleKey
Evaluate
NextOp:=3

Case {/}:
'Set the coordinates for Toggle Key
Keyx:=x+35
Keyy:=15
ToggleStr:=" / "
ToggleKey
Evaluate
NextOp:=4

Case {A}:
'Set the coordinates for Toggle Key
Keyx:=x+20
Keyy:=13
ToggleStr:=" AND "
ToggleKey
Evaluate
NextOp:=5

Case {a}:
'Set the coordinates for Toggle Key
Keyx:=x+20
Keyy:=13
ToggleStr:=" AND "
ToggleKey
Evaluate
NextOp:=5

Case {O}:
'Set the coordinates for Toggle Key
Keyx:=x+27
Keyy:=13
ToggleStr:=" OR "
ToggleKey
Evaluate
NextOp:=6

Case {o}:
'Set the coordinates for Toggle Key
Keyx:=x+27
Keyy:=13
ToggleStr:=" OR "
ToggleKey
Evaluate
NextOp:=6

Case {N}:
'Set the coordinates for Toggle Key
Keyx:=x+33
Keyy:=13
ToggleStr:=" NOT "
ToggleKey
NextOp:=7
Evaluate

Case {n}:
'Set the coordinates for Toggle Key
Keyx:=x+33
Keyy:=13
ToggleStr:=" NOT "
ToggleKey
NextOp:=7
Evaluate

Case {=}:
'Set the coordinates for Toggle Key
Keyx:=x+30
Keyy:=17
ToggleStr:=" = "
ToggleKey
Evaluate
NextOP:=10
SwapVars
SVar1:=SVar2

Case {ENTER}:
'Set the coordinates for Toggle Key
Keyx:=x+30
Keyy:=17
ToggleStr:=" = "
ToggleKey
Evaluate
NextOP:=10
SwapVars
SVar1:=SVar2


Case {C}:
'Set the coordinates for Toggle Key
Keyx:=x+25
Keyy:=11
ToggleStr:=" Clear "
ToggleKey
ClearDisplay
NextOp:=0

Case {c}:
'Set the coordinates for Toggle Key
Keyx:=x+25
Keyy:=11
ToggleStr:=" Clear "
ToggleKey
ClearDisplay
NextOp:=0


Case 8: 'BackSpace Key
'Set the coordinates for Toggle Key
AddNumber

END 'Select
END 'SUB DoKey

'This Routine Toggles the different keys to simulate a key press
Sub ToggleKey
Say @ KeyY,KeyX ToggleStr
wait 2
Say @ KeyY,KeyX ""+ToggleStr
END


'This Routine adds the key to the display if the string is NULL it was a
'backspace character so remove the last character
SUB AddNumber
If LastKey == 8
'Get the Length of the displayed string
I:=Length SVar1
'Get only the first i-1 characters
SVar1:=MidStr SVar1,1,i-1
end else
Key:=NumtoChar LastKey
SVar1:=SVar1+Key
end
i:=Length SVar1
i:=18-i+2
Say @ 11,x+2 " "
Say @ 11,x+i ""+Svar1
END 'SUB Addnumber

'This Routine Evalutes the Operation that was saved before if there is no
'Op stored we just store one and continue.
SUB Evaluate
'Check to see what the operation was
Select NextOp from
case 10:
IVar2:=StrtoNum SVar1
SVar1:=""
ShowAnswer
case 0:
IVar2:=StrtoNum SVar1
SVar1:=""
ShowAnswer
'Add the variables
case 1:
l:=StrtoNum SVar1
IVar2:=l+IVar2
SwapVars
ShowAnswer
'SubTraction
case 2:
l:=StrtoNum SVar1
IVar2:=IVar2-l
SwapVars
ShowAnswer
'Multiplication
case 3:
l:=StrtoNum SVar1
IVar2:=IVar2*l
SwapVars
ShowAnswer
'Division
case 4:
l:=StrtoNum SVar1
IVar2:=IVar2/l
SwapVars
ShowAnswer
'AND
case 5:
l:=StrtoNum SVar1
IVar2:=IVar2 AND l
SwapVars
ShowAnswer
'OR
case 6:
l:=StrtoNum SVar1
IVar2:=IVar2 OR l
SwapVars
ShowAnswer
case 7:
l:=StrtoNum SVar1
IVar2:=NOT l
SwapVars
ShowAnswer
end
END

'This Routine will Display the Ticker Tape
SUB TickerTape
cls
END

'This routine will show an answer in the calculator's window
SUB ShowAnswer
i:=Length SVar2
i:=18-i+2
Say @ 11,x+2 " "
Say @ 11,x+i ""+Svar2
END 'ShowAnswer

'This Routine Clears the display of the Calculator
SUB ClearDisplay
SVar1:=""
SVar2:=""
i:=Length SVar1
i:=18-i+2
Say @ 11,x+2 " "
Say @ 11,x+i ""+Svar1
END 'ClearDisplay

SUB SwapVars
SVar2:=LongtoStr IVar2
SVar1:=SVar2

IVar1:=IVar2
SVar1:=""
END