Computer Science Canada How would you use a function for a calculator |
Author: | rbb [ Tue May 20, 2003 10:18 am ] |
Post subject: | How would you use a function for a calculator |
Quote: import GUI in "%oot/lib/GUI"
View.Set ("graphics:290;230") drawfill (100, 100, grey, grey) colorback (grey) color (black) procedure b1 cls put "1" end b1 procedure b2 cls put "2" end b2 procedure b3 cls put "3" end b3 procedure b4 cls put "4" end b4 procedure b5 cls put "5" end b5 procedure b6 cls put "6" end b6 procedure b7 cls put "7" end b7 procedure b8 cls put "8" end b8 procedure b9 cls put "9" end b9 procedure b10 cls put "/" end b10 procedure b11 cls put "X" end b11 procedure b12 cls put "+" end b12 procedure b13 cls put "-" end b13 procedure b14 cls put "0" end b14 procedure b15 cls put "=" end b15 procedure b16 cls put "+/-" end b16 loop var button1 : int := GUI.CreateButton (10, 100, 60, "1", b1) var button2 : int := GUI.CreateButton (80, 100, 60, "2", b2) var button3 : int := GUI.CreateButton (150, 100, 60, "3", b3) var button4 : int := GUI.CreateButton (10, 70, 60, "4", b4) var button5 : int := GUI.CreateButton (80, 70, 60, "5", b5) var button6 : int := GUI.CreateButton (150, 70, 60, "6", b6) var button7 : int := GUI.CreateButton (10, 40, 60, "7", b7) var button8 : int := GUI.CreateButton (80, 40, 60, "8", b8) var button9 : int := GUI.CreateButton (150, 40, 60, "9", b9) var button10 : int := GUI.CreateButton (220, 100, 60, "/", b10) var button11 : int := GUI.CreateButton (220, 70, 60, "X", b11) var button12 : int := GUI.CreateButton (220, 40, 60, "-", b12) var button13 : int := GUI.CreateButton (220, 10, 60, "+", b13) var button14 : int := GUI.CreateButton (80, 10, 60, "0", b14) var button15 : int := GUI.CreateButton (150, 10, 60, "=", b15) var button16 : int := GUI.CreateButton (10, 10, 60, "+/-", b16) exit when GUI.ProcessEvent end loop |
Author: | tum_twish [ Tue May 20, 2003 7:36 pm ] |
Post subject: | |
You can use it when making calculations (ie. add function) |
Author: | rbb [ Wed May 21, 2003 10:01 am ] |
Post subject: | I meant... |
I meant how do you m,ake a function work, for example how would you make the add button add and teh subtract button subtract |
Author: | Tony [ Wed May 21, 2003 2:15 pm ] |
Post subject: | |
well the easiest calculator will also have two text fields... for an addition function, it will take the values from both textfields and add then together, then return a value and place it into the 3rd text field. Similar with the rest |