Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 button problem 2
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kirsty_16




PostPosted: Wed Jan 14, 2004 1:22 pm   Post subject: button problem 2

This what I have so far. This is my first time with buttons. I usually try to avoid them but this time i couldn't. Is there any easier way of doing this?? Confused here it is...

import GUI in "%oot/lib/GUI"
proc choice_A
locate (2,3)
put "You chose 'Planets'"
end choice_A


proc choice_B
locate (2, 3)
put "You chose 'Time'"
end choice_B

proc choice_C
locate (2, 3)
put "You chose 'Disasters'"
end choice_C

proc choice_D
locate (2, 3)
put "You chose 'Bands'"
end choice_D

proc makethebuttons
var button1 : int := GUI.CreateButton (90, 700, 150, "A", choice_A)
var button2 : int := GUI.CreateButton (90, 650, 130, "B", choice_B)
var button3 : int := GUI.CreateButton (90, 600, 110, "C", choice_C)
var button4 : int := GUI.CreateButton (90, 550, 90, "D", choice_D)
var button7 : int := GUI.CreateButton (90, 500, 70, "Quit", GUI.Quit)
end makethebuttons

procedure main
locate (3, 5)
put " "
put ""
makethebuttons
end main

main

loop
exit when GUI.ProcessEvent
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Wed Jan 14, 2004 6:51 pm   Post subject: (No subject)

if you dont like using GUI, you can use Mouse.Where and check if user clicks inside the box yourself
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kanetix




PostPosted: Thu Jan 15, 2004 8:36 pm   Post subject: (No subject)

for mousewhere(x,y, _) <-- what is the third value?
Neja




PostPosted: Thu Jan 15, 2004 11:59 pm   Post subject: (No subject)

The third value is button (button=1 when the button is being pressed)
BryX




PostPosted: Fri Jan 16, 2004 3:25 pm   Post subject: (No subject)

there is an easier way, the way i did it was this....this way u don't have to ahve seperate procedures for each answer, u can use the same ones for every question

code:
/*--------Answer key----*/
body proc answer1
    clear
    answer := 1
    return
end answer1
body proc answer2
    clear
    answer := 2
    return
end answer2
body proc answer3
    clear
    answer := 3
    return
end answer3
body proc answer4
    clear
    answer := 4
    return
end answer4

%-----Question 1-----%
    Font.Draw ("1)Where do you live?", 0, maxy - 80, FontID2, green)
    var abutton_1a : int := GUI.CreateButtonFull (maxx div 2 - 300, 400, 100, "Barrie", answer1, 50, '^1', true)
    var abutton_1b : int := GUI.CreateButtonFull (maxx div 2 - 300 + 100, 400, 100, "Toronto", answer2, 50, '^2', true)
    var abutton_1c : int := GUI.CreateButtonFull (maxx div 2 - 300 + 200, 400, 100, "Somewhere", answer3, 50, '^3', true)
    var abutton_1d : int := GUI.CreateButtonFull (maxx div 2 - 300 + 300, 400, 100, "Somewhere Else", answer4, 50, '^4', true)
    loop
        exit when GUI.ProcessEvent or exitvar = true
        if answer = 1 then
            locate (17, 62)
            put "cool, I live in Barrie too"
            delay (2000)
            aq1 := "Barrie"
            answer := 0
            exit
        elsif answer = 2 then
            locate (17, 62)
            put "cool, I live in Barrie."
            delay (2000)
            aq1 := "Toronto"
            answer := 0
            exit
        elsif answer = 3 then
            aq1 := "Somewhere"
            answer := 0
            exit
        elsif answer = 4 then
            aq1 := "Somewhere Else"
            answer := 0
            exit
        end if
    end loop
    GUI.Disable (abutton_1a)
    GUI.Disable (abutton_1b)
    GUI.Disable (abutton_1c)
    GUI.Disable (abutton_1d)
    clear

%-----Question 2-----%
    Font.Draw ("2)Do you live in the city or the country?", 0, maxy - 80, FontID2, green)
    var abutton_2a : int := GUI.CreateButtonFull (maxx div 2 - 300, 400, 100, "City", answer1, 50, '^1', true)
    var abutton_2b : int := GUI.CreateButtonFull (maxx div 2 - 300 + 100, 400, 100, "Country", answer2, 50, '^2', true)
    loop
        exit when GUI.ProcessEvent or exitvar = true
        if answer = 1 then
            locate (17, 62)
            put "cool, i live in the city too"
            delay (2000)
            aq2 := "City"
            answer := 0
            exit
        elsif answer = 2 then
            locate (17, 62)
            put "I live in the City but I also have a horse farm in the county"
            delay (2000)
            aq2 := "Country"
            answer := 0
            exit
        end if
    end loop
    GUI.Disable (abutton_2a)
    GUI.Disable (abutton_2b)
    clear
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: