I am getting a number (for a visual calculator) useing:
If One.ContainsPoint ( MouseX, MouseY ) And LeftPressed Then //LeftPressed Then SecondPart=1 ClearMouseEvents() stillrunning=False
This works in so far as geting a single (ie 0 to 9) but how do I build a larger number such as 11 or 111
Be here now
You are forcing the user to input keys according to your program, such as:
GetInput()GetOperator()GetInput2()
What you need to do is let the user decide what to input, and have the program respond according to the key pressed. One way to do that is by using states. You'd use one input routine that would simply return the key the user clicked on and depending on the state, add that to the first number or second number. Here is a rough outline:
state = 1While Key <> "=" Key = UserInput() If [Key is a number] Then If State = 1 then FirstNumber = Firstnumber * 10 + Key Else SecondNumber = SecondNumber * 10 + Key End If Else Operator = Key State = 2 End IfEnd WhileShowAnswer()
As you see the loop begins by waiting for the = sign. For each iteration it calls the UserInput() function that returns the value of the key the user hit. If the key is a number it does one thing, or if the key is an operator is does another. (That [Key is a number] won't work as shown, you'll need to add the proper test...) When the = sign is hit it breaks out of the loop to show the answer. That is not working code, but a general idea of how to tackle the problem.... Good Luck!
Mmm, after seeing that you were making a calculator, I decided to try making one myself. This is what I had for building numbers.
Parameters:
CurNum:
The current number shown on the display of the calculator.
Button:
The one digit number of the button pressed.
This function has a built-in error: It will not go above four digits. This is to try to avoid incurring the wrath of the Int32 error gods.
Hope this works for you!
hello
I'm with a project for school, to make a calculator.
can you put here the one you have done?
This is verry much a work in progress and is not working as of this moment, but I have uploaded it so you are welcome to have a look and see if there is anything of use to you in there. Could I ask that if you get somthing similar upand working that I may allso see the code ?
Terry
I'll post my calculator as soon as it's finished. I've only got the operators and the display left. Well, that and I have to add the decimal point...
Unlike terryb's calculator, this calculator has the ten digits, a decimal point, the four basic operators, and an equals button. I'll add more to it over time, but it's best to start simple so that you can feel what you're working with, what techniques work, and how using different variables affects your program.
Finished with the uttermost basics. This calculator supports positive integer numbers up to 9999. It cannot do decimals or negatives yet.It does refresh the display, rather sloppily* though. Improving that is on the list.It doesn't have the ability to do things like 1+1+1= yet, you have to press 1+1=+1=.The ability to press = to repeat the last operation is not yet available. This means that 1+1== does not give three, it gives error.Other than that, enjoy!
*sloppily in this case just means that the timing can make no sense.
Bieing new to phrogram I'm at a loss to understand the following code from Megahand's calcutor ;code fragment -
"Buttons.Item((I - 1) * 4 + J).MoveTo(J * 5 + ((J - 1) * 25), 20 + I * 5 + ((I - 1) * 25)) Buttons.Item((I - 1) * 4 + J).SetRotationOffset(-12.5, -12.5) Buttons.Item((I - 1) * 4 + J).Visible = True"
Can some one please explain,
I can see that this code is placing and showing the buttons but thats about all !
PS Thank you Mehahand for sharing you code
This is very cool!
Megahand will know best how this code works but within a 4 by 4 nested loop, it does look like it is populating and placing the buttons from the spritelist. When you hover over code in Phrogram, you will see a pop-up tip on what the method does. On the second line of this excerpt, It looks like Megahand is using SetRotationOffset to compensate for the bars in the column and row bars that are visible in the backdrop image.
Look forward to seeing more functionality in this program - it would have been a great entry into our math contest a year or two back!
True, but I'm working on that......and negatives......and decimals......and more functions......and making the calculator look a little nicer......and memory. And fractions.
Oh, and, yes, that is what the nested Fors do, and the rotational offset was because I was originally planning to make the buttons turn 180 degrees when you pressed them. The problem was that the numbers themselves also rotated. You can delete the offset setting line.
PS You're welcome, TerryB :D
I'm so new in this, my calculator is going to be much more simple
I just want to ask the user for a number then the operation he wants to do and then the other number. and if the presses F to end the program.
My problem is to finish the program when F is pressed, I've been unable to do that.