Oops... I should of paid more attention.
Quote: "1.Whats a flag?"
I call them switches but it's basically the same thing as Jasonhtml explained.
Quote: "2.TDK_Man said I shouldn't use 'goto' but your version still uses it. Is it ok there? How else would I go back to Start?"
You don't have to have "Start" at all. All you need to do is reset the arrays. And there's no need to redraw the whole screen just the answer box.
Quote: "3.What's the point of the 'end' command in there, wont it never happen/get executed??"
In Pro if you don't have "end" before any functions it'll show an error if it hits a function without calling the function. In Classic it will error out but not show anything. "End" just assures that the user won't see an error regardless and is a proper way to end the program (rather than producing an error). Adding "end" after a loop without an "exit" although not needed is a "just in case something horrible happens" situation.
Quote: "4.I made the function resturn a value so you could set it = to 1...is this right?"
Yes. It works great.
Quote: "5.Did I use arrays right...how else could I change the variables globally in functions...should I have used gosubs?"
If your using Pro you don't have to make that first array since you only use one element you can just make a variable global by using "global TextSpacing". "Gosub" wouldn't work too well in there. "Gosubs" are used like functions... they run then "return" back to the line under the "gosub".
It's best to just remove the last "goto":
Rem Calc. 1.0 Created 1/12/07
Rem Simple Global Array
Dim TextSpacing(1)
TextSpacing(1)=5
Rem Determine the Numbers Being Used(1st and 2nd)
Dim Numbers#(6)
Rem Determine to Add, Subtract, Multiply, or Divide
Dim CaclulationType(4)
Rem Ink White For When the Program Revisits Start
Ink RGB(255,255,255),0
Rem Answer Box
Box 0 , 0 , screen width() , screen height()*.154
Rem Clear Buttom
Box screen width()*.364 , screen height()*.231 , screen width()*.636 , screen height()*.308
Rem 7, 6, etc. Button
Box screen width()*.182 , screen height()*.385 , screen width()*.273 , screen height()*.462
Box screen width()*.364 , screen height()*.385 , screen width()*.455 , screen height()*.462
Box screen width()*.545 , screen height()*.385 , screen width()*.636 , screen height()*.462
Box screen width()*.727 , screen height()*.385 , screen width()*.818 , screen height()*.462
Box screen width()*.182 , screen height()*.539 , screen width()*.273 , screen height()*.615
Box screen width()*.364 , screen height()*.539 , screen width()*.455 , screen height()*.615
Box screen width()*.545 , screen height()*.539 , screen width()*.636 , screen height()*.615
Box screen width()*.727 , screen height()*.539 , screen width()*.818 , screen height()*.615
Box screen width()*.182 , screen height()*.692 , screen width()*.273 , screen height()*.769
Box screen width()*.364 , screen height()*.692 , screen width()*.455 , screen height()*.769
Box screen width()*.545 , screen height()*.692 , screen width()*.636 , screen height()*.769
Box screen width()*.727 , screen height()*.692 , screen width()*.818 , screen height()*.769
Box screen width()*.182 , screen height()*.846 , screen width()*.273 , screen height()*.923
Box screen width()*.364 , screen height()*.846 , screen width()*.455 , screen height()*.923
Box screen width()*.545 , screen height()*.846 , screen width()*.636 , screen height()*.923
Rem Make Text Black
Ink RGB(0,0,0), 0
Rem Clear Text
Center Text 325 , 120 , "Clear"
Rem 7, 6, etc. Text
Center Text 145 , 195 , "7"
Center Text 262 , 195 , "8"
Center Text 379 , 195 , "9"
Center Text 496 , 195 , "+"
Center Text 145 , 268 , "4"
Center Text 262 , 268 , "5"
Center Text 379 , 268 , "6"
Center Text 496 , 268 , "-"
Center Text 145 , 343 , "1"
Center Text 262 , 343 , "2"
Center Text 379 , 343 , "3"
Center Text 496 , 343 , "*"
Center Text 145 , 416 , "0"
Center Text 262 , 416 , "="
Center Text 379 , 416 , "/"
Rem Main Loop
Do
` Reset all arrays and make a new answer box
if ClearScreen(234 , 407 , 114 , 152)=1
` Reset arrays
TextSpacing(1)=5
for t=0 to 6:Numbers#(t)=0:next t
for t=0 to 4:CaclulationType(t)=0:next t
` Make a new answer box
Ink RGB(255,255,255),0
Box 0 , 0 , screen width() , screen height()*.154
Ink RGB(0,0,0), 0
endif
NumberClick(7 , 114 , 173 , 183 , 221)
NumberClick(8 , 234 , 290 , 183 , 221)
NumberClick(9 , 344 , 407 , 183 , 221)
SymbolClick("+" , 464 , 524 , 183 , 221)
NumberClick(4 , 114 , 173 , 256 , 294)
NumberClick(5 , 234 , 290 , 256 , 294)
NumberClick(6 , 344 , 407 , 256 , 294)
SymbolClick("-" , 464 , 524 , 256 , 294)
NumberClick(1 , 114 , 173 , 329 , 367)
NumberClick(2 , 234 , 290 , 329 , 367)
NumberClick(3 , 344 , 407 , 329 , 367)
SymbolClick("*" , 464 , 524 , 329 , 367)
NumberClick(0 , 114 , 173 , 402 , 440)
CalculateAnswer(234 , 289 , 402 , 440)
SymbolClick("/" , 344 , 407 , 402 , 440)
Loop
end
REM FUNCTIONS
Rem Clear Button
Function ClearScreen(LeftX , RightX , TopY , BottomY)
If Mouseclick()=1 and mousex()>LeftX and mousex()<RightX and mousey()>TopY and mousey()<BottomY
ClearPress=1
endif
endfunction ClearPress
Rem Number Buttons(Up to 3 Digits)
Function NumberClick(Value , LeftX , RightX , TopY , BottomY)
If Mouseclick()=1 and mousex()>LeftX and mousex()<RightX and mousey()>TopY and mousey()<BottomY
Text TextSpacing(1),28,Str$(Value)
wait 150
If Numbers#(2)>9.999
Numbers#(2)=(10*(Numbers#(2))) : Numbers#(2)=(Numbers#(2)+Value)
else
If Numbers#(2)>0
Numbers#(2)=(10*(Numbers#(2))) : Numbers#(2)=(Numbers#(2)+Value)
else
If Numbers#(1)>0 and (CaclulationType(1)=1 or CaclulationType(2)=1 or CaclulationType(3)=1 or CaclulationType(4)=1)
Numbers#(2)=Value
else
If Numbers#(1)>9.999
Numbers#(1)=(10*(Numbers#(1))) : Numbers#(1)=(Numbers#(1)+Value)
else
Numbers#(1)=(10*(Numbers#(1))) : Numbers#(1)=(Numbers#(1)+Value)
endif
endif
If Numbers#(1)=0
Numbers#(1)=Value
endif
endif
endif
TextSpacing(1)=TextSpacing(1) + 10
endif
endfunction
Rem Operation Buttons
Function SymbolClick(Symbol$ , LeftX , RightX , TopY , BottomY)
If Mouseclick()=1 and mousex()>LeftX and mousex()<RightX and mousey()>TopY and mousey()<BottomY
Text TextSpacing(1),28,Symbol$
wait 150
If Symbol$="+"
CaclulationType(1)=1
endif
If Symbol$="-"
CaclulationType(2)=1
endif
If Symbol$="*"
CaclulationType(3)=1
endif
If Symbol$="/"
CaclulationType(4)=1
endif
TextSpacing(1)=TextSpacing(1) + 10
endif
endfunction
Rem Equal Button
function CalculateAnswer(LeftX , RightX , TopY , BottomY)
If Mouseclick()=1 and mousex()>LeftX and mousex()<RightX and mousey()>TopY and mousey()<BottomY
Text TextSpacing(1),28,"="
TextSpacing(1)=TextSpacing(1) + 10
If CaclulationType(1)=1
Text TextSpacing(1),28,str$(Numbers#(1)+Numbers#(2))
endif
If CaclulationType(2)=1
Text TextSpacing(1),28,str$(Numbers#(1)-Numbers#(2))
endif
If CaclulationType(3)=1
Text TextSpacing(1),28,str$(Numbers#(1)*Numbers#(2))
endif
If CaclulationType(4)=1
Text TextSpacing(1),28,str$(Numbers#(1)/Numbers#(2))
endif
wait 150
TextSpacing(1)=TextSpacing(1) + 50
Numbers#(1)=0
Numbers#(2)=0
CaclulationType(1)=0
CaclulationType(2)=0
CaclulationType(3)=0
CaclulationType(4)=0
endif
endfunction