Computer Science Canada

GUI culminating activity

Author:  Bruski [ Wed Jun 11, 2003 7:37 pm ]
Post subject:  GUI culminating activity

Hello everyone, im just having some problems with this GUI thing, i wanted to use the GUI. commands because it seem easier than writting all the code that my teacher gave me. I just had some problems....i want to put a cost of a cd in a field and then press a button and calc the total with tax....anyone got any ideas here is what i have soo far...

code:

import GUI
 
View.Set ("graphics:600;300,nobuttonbar")

var nameTextField, addressTextField, cityTextField, provinceTextField, costTextField : int
var total, tax, cost : real

procedure NameEntered (text : string)
        GUI.SetSelection (addressTextField, 0, 0)
        GUI.SetActive (addressTextField)
end NameEntered

procedure AddressEntered (text : string)
        GUI.SetSelection (cityTextField, 0, 0)
        GUI.SetActive (cityTextField)
end AddressEntered

procedure CityEntered (text: string)
        GUI.SetSelection (provinceTextField, 0, 0)
        GUI.SetActive (provinceTextField)
end CityEntered

procedure ProvinceEntered (text: string)
        GUI.SetSelection(costTextField, 0, 0)
        GUI.SetActive (costTextField)
end ProvinceEntered

procedure CostCD (text: string)
        locatexy(
        get cost
end CostCD




GUI.SetBackgroundColor (yellow)
%declare fields & labels
nameTextField := GUI.CreateTextFieldFull (65, 250, 100, "",
        NameEntered, GUI.INDENT, 0, 0)
var nameLabel := GUI.CreateLabelFull (55, 250, "Name:", 0, 0,
        GUI.RIGHT, 0)
       
addressTextField := GUI.CreateTextFieldFull (65, 220, 100, "",
        AddressEntered, GUI.INDENT, 0, 0)
var addressLabel := GUI.CreateLabelFull (55, 220, "Address:", 0, 0,
        GUI.RIGHT, 0)
       
cityTextField := GUI.CreateTextFieldFull (65, 190, 100, "",
        CityEntered, GUI.INDENT, 0, 0)
var cityLabel := GUI.CreateLabelFull (55, 190, "City:", 0, 0,
        GUI.RIGHT, 0)
       
provinceTextField := GUI.CreateTextFieldFull (65, 160, 100, "",
        ProvinceEntered, GUI.INDENT, 0, 0)
var provinceLabel := GUI.CreateLabelFull (55, 160, "Province:", 0, 0,
        GUI.RIGHT, 0)
       
cost := GUI.CreateTextFieldFull (65, 130, 100, "",
        CostCD, GUI.INDENT, 0, 0)
var costLabel := GUI.CreateLabelFull (55, 130, "CD Cost:", 0, 0,
        GUI.RIGHT, 0)       

var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
loop
    exit when GUI.ProcessEvent
end loop




anything would be appreciated thanks alot

alex Crying or Very sad

Author:  Andy [ Wed Jun 11, 2003 7:53 pm ]
Post subject: 

why do u want the cost in a text field? do u mean text box?

Author:  Bruski [ Wed Jun 11, 2003 7:56 pm ]
Post subject: 

i want to enter the cost of a cd in one field...then press calculate and it takes the cost of the cd and calcualtes the subtotal total gst pst etc Razz

Author:  Andy [ Wed Jun 11, 2003 7:59 pm ]
Post subject: 

ooo sry i mis read

Author:  Bruski [ Wed Jun 11, 2003 8:03 pm ]
Post subject: 

anyway to help me?

Author:  Andy [ Wed Jun 11, 2003 8:05 pm ]
Post subject: 

it think this is what u want


code:

import GUI

View.Set ("graphics:600;300,nobuttonbar")

var nameTextField, addressTextField, cityTextField, provinceTextField, costTextField : int
var total, tax, cost : real
tax:=0.15
colorback(yellow)

procedure NameEntered (text : string)
    GUI.SetSelection (addressTextField, 0, 0)
    GUI.SetActive (addressTextField)
end NameEntered

procedure AddressEntered (text : string)
    GUI.SetSelection (cityTextField, 0, 0)
    GUI.SetActive (cityTextField)
end AddressEntered

procedure CityEntered (text : string)
    GUI.SetSelection (provinceTextField, 0, 0)
    GUI.SetActive (provinceTextField)
end CityEntered

procedure ProvinceEntered (text : string)
    GUI.SetSelection (costTextField, 0, 0)
    GUI.SetActive (costTextField)
end ProvinceEntered

procedure CostCD (text : string)
total:= strreal(text)+strreal(text)*tax
locate(12,1)
put "total is",total
end CostCD




GUI.SetBackgroundColor (yellow)
%declare fields & labels
nameTextField := GUI.CreateTextFieldFull (65, 250, 100, "",
    NameEntered, GUI.INDENT, 0, 0)
var nameLabel := GUI.CreateLabelFull (55, 250, "Name:", 0, 0,
    GUI.RIGHT, 0)

addressTextField := GUI.CreateTextFieldFull (65, 220, 100, "",
    AddressEntered, GUI.INDENT, 0, 0)
var addressLabel := GUI.CreateLabelFull (55, 220, "Address:", 0, 0,
    GUI.RIGHT, 0)

cityTextField := GUI.CreateTextFieldFull (65, 190, 100, "",
    CityEntered, GUI.INDENT, 0, 0)
var cityLabel := GUI.CreateLabelFull (55, 190, "City:", 0, 0,
    GUI.RIGHT, 0)

provinceTextField := GUI.CreateTextFieldFull (65, 160, 100, "",
    ProvinceEntered, GUI.INDENT, 0, 0)
var provinceLabel := GUI.CreateLabelFull (55, 160, "Province:", 0, 0,
    GUI.RIGHT, 0)

costTextField := GUI.CreateTextFieldFull (65, 130, 100, "",
    CostCD, GUI.INDENT, 0, 0)
var costLabel := GUI.CreateLabelFull (55, 130, "CD Cost:", 0, 0,
    GUI.RIGHT, 0)

var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
loop
    exit when GUI.ProcessEvent
end loop


Author:  Bruski [ Wed Jun 11, 2003 8:12 pm ]
Post subject: 

man your way too cool...thx alot..ima check it

Author:  Bruski [ Wed Jun 11, 2003 8:13 pm ]
Post subject: 

hmm is there anyway to put that in a text field like the others and have it calc by a button? Embarassed

Author:  Andy [ Wed Jun 11, 2003 8:13 pm ]
Post subject: 

haha, np, anytime although cause of exams, i'm not gonna be on very often next week

Author:  Bruski [ Wed Jun 11, 2003 8:16 pm ]
Post subject: 

yea i just need it by fri cuz its due monday...i just need a simple example and ill get the rest...thx again

Author:  Homer_simpson [ Wed Jun 11, 2003 10:25 pm ]
Post subject: 

code:
import GUI

View.Set ("graphics:600;300,nobuttonbar")

var nameTextField, addressTextField, cityTextField, provinceTextField, costTextField : int
var total, tax, cost : real
var output := ""
var draw : boolean := false
tax := 0.15
colorback (black)

procedure NameEntered (text : string)
    GUI.SetSelection (addressTextField, 0, 0)
    GUI.SetActive (addressTextField)
end NameEntered

procedure AddressEntered (text : string)
    GUI.SetSelection (cityTextField, 0, 0)
    GUI.SetActive (cityTextField)
end AddressEntered

procedure CityEntered (text : string)
    GUI.SetSelection (provinceTextField, 0, 0)
    GUI.SetActive (provinceTextField)
end CityEntered

procedure ProvinceEntered (text : string)
    GUI.SetSelection (costTextField, 0, 0)
    GUI.SetActive (costTextField)
end ProvinceEntered

procedure emptyf (text : string)
    output := ""
end emptyf

procedure CostCD (text : string)
    total := strreal (text) + strreal (text) * tax
    output := realstr (total, 10)
end CostCD

procedure caculate ()
    draw := true
end caculate

GUI.SetBackgroundColor (yellow)
%declare fields & labels
nameTextField := GUI.CreateTextFieldFull (65, 250, 100, "", NameEntered, GUI.INDENT, 0, 0)
var nameLabel := GUI.CreateLabelFull (55, 250, "Name:", 0, 0, GUI.RIGHT, 0)

addressTextField := GUI.CreateTextFieldFull (65, 220, 100, "", AddressEntered, GUI.INDENT, 0, 0)
var addressLabel := GUI.CreateLabelFull (55, 220, "Address:", 0, 0, GUI.RIGHT, 0)

cityTextField := GUI.CreateTextFieldFull (65, 190, 100, "", CityEntered, GUI.INDENT, 0, 0)
var cityLabel := GUI.CreateLabelFull (55, 190, "City:", 0, 0, GUI.RIGHT, 0)

provinceTextField := GUI.CreateTextFieldFull (65, 160, 100, "", ProvinceEntered, GUI.INDENT, 0, 0)
var provinceLabel := GUI.CreateLabelFull (55, 160, "Province:", 0, 0, GUI.RIGHT, 0)

var taxtf := GUI.CreateTextFieldFull (65, 90, 100, "", emptyf, GUI.INDENT, 0, 0)


costTextField := GUI.CreateTextFieldFull (65, 130, 100, "", CostCD, GUI.INDENT, 0, 0)
var gtax := GUI.CreateLabelFull (55, 90, "tax:", 0, 0,
    GUI.RIGHT, 0)

var costLabel := GUI.CreateLabelFull (55, 130, "CD Cost:", 0, 0, GUI.RIGHT, 0)
var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)

var calcb : int := GUI.CreateButton (260, 10, 0, "Caclulate", caculate)
loop
    if draw then
        GUI.SetText (taxtf, output)
        draw := false
    end if
    exit when GUI.ProcessEvent
end loop

this isn't a very clean code(cuz i made it fast) but it does the job...

Author:  Bruski [ Thu Jun 12, 2003 6:22 am ]
Post subject: 

thank you thank you thank you....you guys are too good.... Very Happy


: