Making a calculator using GUI
Author |
Message |
Banished_Outlaw
|
Posted: Fri Mar 23, 2007 9:48 pm Post subject: Making a calculator using GUI |
|
|
Hi, I am a grade 11 student learning Turing.
Every year in our programming course, we have to make a program as our final project that is worth 30% of our mark.
This year, I am planning to make a calculator using the GUI features in Turing, just like the calculator we have on Windows.
We haven't learn't GUI yet but using the help section I have learnt how to make buttons.
I am thinking of using arrays to do all the calculations. The only problem I am have is how do I display the results and the numbers in my program. I tried making a TextFeild button but that button can only be used with strings not integers (atleast that's what I think)
My second problem is how to make the various procedures for some of the buttons like add, multiply, divide etc.
All I have so far is:
Quote:
import GUI
var C : int := 0
View.Set ("graphics:260;225; title: Calculator")
drawfillbox (0, 0, 260, 225, grey)
proc backspace
cls
end backspace
proc clearit
cls
put C
end clearit
proc Quit
GUI.Quit
View.Set ("invisible")
end Quit
var number : string
var BS : int := GUI.CreateButtonFull (65, 140, 0, "Backspace", backspace, 0, chr (8), true)
var clear : int := GUI.CreateButtonFull (155, 140, 0, "C", clearit, 0, "C", true)
var OFF : int := GUI.CreateButtonFull (200, 140, 0, "Quit", Quit, 0, chr (27), true)
var indentFrame : int := GUI.CreateFrame (5, 163, 60, 140, GUI.INDENT)
var add : int := GUI.CreateButtonFull (65, 140, 0, "+", additon, 0, chr (8), true)
loop
exit when GUI.ProcessEvent
end loop
I still have a couple of months before the project is due but I thought since the program is not that easy, I should start making it right now.
Any suggestions will be greatly appreciated. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
octopi
|
Posted: Sat Mar 24, 2007 10:40 am Post subject: Re: Making a calculator using GUI |
|
|
Try using intstr();, it will convert your int into a string. |
|
|
|
|
|
Banished_Outlaw
|
Posted: Sat Mar 24, 2007 12:52 pm Post subject: Re: Making a calculator using GUI |
|
|
thank you Octopi, that might work. |
|
|
|
|
|
Banished_Outlaw
|
Posted: Sun Mar 25, 2007 1:02 am Post subject: Re: Making a calculator using GUI |
|
|
Never mind, strings are alphanumerics so the text field should accept numbers as the input...... |
|
|
|
|
|
Banished_Outlaw
|
Posted: Tue Mar 27, 2007 9:36 am Post subject: Re: Making a calculator using GUI |
|
|
Does anyone know how i can use the text input by the user in the text field?? |
|
|
|
|
|
Cervantes
|
Posted: Tue Mar 27, 2007 10:10 am Post subject: Re: Making a calculator using GUI |
|
|
Banished_Outlaw @ Sun Mar 25, 2007 1:02 am wrote: Never mind, strings are alphanumerics so the text field should accept numbers as the input......
You can use strintok and strint to convert strings to integers (and not crashing if unacceptable input is given). |
|
|
|
|
|
Banished_Outlaw
|
Posted: Tue Mar 27, 2007 3:52 pm Post subject: Re: Making a calculator using GUI |
|
|
code: |
import GUI
var numberTextField : int
proc numbers (text : string)
GUI.SetSelection (numberTextField, 0, 0)
GUI.SetActive (numberTextField)
end numbers
var NumberScreen := GUI.CreateTextFieldFull (6, 190, 245, "", numbers, GUI.INDENT, 0, 0)
loop
exit when GUI.ProcessEvent
end loop
put " Hello = ", GUI.GetText (strint (NumberScreen) %Gives Error that First argument for strint must be string type
|
Apparently the only way you can call text from a button is by using the command GUI.GetText and for that you have to call in the name of the Text field button where the value has been derived from. And since buttons are always integers, I cant use strint or strintok, I cannot use intstr either because the procedure for the text field button is string...
Anyone have any clue how I can overcome this problem?, or if theres any other way to call the text typed in by the user in the text field? |
|
|
|
|
|
|
|