# Small basic - Making a calculator with specific rules. • ### Question

• hey so im making a calculator, but parts aren't working and i cant figure some other things out, so please could you help me fix it and make the code as original as possible. so the rules are the it cant calculate any number over 999 whether its the answer or in the equation, this should be reported as an error. for example 990 + 9 = 999 which is fine, but 990 + 10 = error is what should happen, also something like 1000+1= error should be there as well. also could you make two different codes for this part, such as one says the error when you enter  a value over 999 and the other is when the answer is over 999. next rule is it only has to be able to subtract and add and a clear button that clears all the data from the last equation. And please note that it has to say error when an equation is over 999 or under 0. here is my code and please if you could explain everything about it this would help so much.

GraphicsWindow.Title = "Calculator"
GraphicsWindow.Show()
GraphicsWindow.Height = "200"
GraphicsWindow.Width = "265"

Zero = Controls.AddButton(" 0 ", 30,120)
Point = Controls.AddButton(" .  ", 62,120)
Clear = Controls.AddButton(" C  ", 120,30)

For i = 1 to 9
x = 30*(1+Math.Remainder(i-1,3))
y = 30*(1+Math.Floor((i-1)/3))
buttonvalue[i] = i
EndFor

buttonvalue = "1"
buttonvalue = "2"
buttonvalue = "3"
buttonvalue = "4"
buttonvalue = "5"
buttonvalue = "6"
buttonvalue = "7"
buttonvalue = "8"
buttonvalue = "9"
buttonvalue = "0"
buttonValue = "="
buttonValue = "+"
buttonValue = "-"

Controls.ButtonClicked = OnButtonClicked

valueCurrent = ""
operator = ""

Sub OnButtonClicked
buttonClicked = Controls.LastClickedButton
For i = 1 To Array.GetItemCount(button)
If (button[i] = buttonClicked) Then
valueCurrent = Text.Append(valueCurrent,buttonValue[i])
EndIf
EndFor
If buttonClicked = Plus Then
value1 = valueCurrent
valueCurrent = ""
operator = "+"
ElseIf buttonClicked = Minus Then
value1 = valueCurrent
valueCurrent = ""
operator = "-"
ElseIf buttonClicked = Equals Then
value2 = valueCurrent
If (operator = "+") Then
valueCurrent = value1+value2
ElseIf (operator = "-") Then
valueCurrent = value1-value2
EndIf
EndIf
EndSub

thank you guys so much for helping

Sunday, February 9, 2014 7:49 PM

• Hey unbitible, nice calculator.

To do this I chose to create an error check subroutine that checks the variable "currentValue" and if an error occurs return this result in a message box.

I just called this sub at any point in the program where I wanted to check an error.

Here's the full sample: RBM261

Here's the sub:

```Sub CheckValueCurrent
If valueCurrent < 0 Or valueCurrent > 999 Then
valueCurrent = ""