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

Username:   Password: 
 RegisterRegister   
 GUI button.... How to do an if GUI button pressed
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nick4563




PostPosted: Mon Jan 17, 2011 7:58 pm   Post subject: GUI button.... How to do an if GUI button pressed

What is it you are trying to achieve?
I want to add 1 to the value of i if my GUI Button is pressed


What is the problem you are having?
Don't know what to do for the if statement

Describe what you have tried to solve this problem
Not much I'm stumped BooHoo


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


import GUI
var NQuestion : array 1 .. 9 of string
NQuestion (1) := "Question 2"
var i : int
i := 1

procedure NextQ
    put NQuestion (i)
end NextQ

View.Set ("graphics:300;200,nobuttonbar ")
var next_question : int := GUI.CreateButtonFull (50, 10, 0, "Next Question",
    NextQ, 0, '^D', true)
var quitBtn : int := GUI.CreateButton (200, 10, 0, "Quit", GUI.Quit)
loop
    exit when GUI.ProcessEvent
end loop

%if (WHAT DO I PUT HERE)
    then
    i += 1
end if



Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
TerranceN




PostPosted: Mon Jan 17, 2011 8:18 pm   Post subject: RE:GUI button.... How to do an if GUI button pressed

Your program will never reach that if statement until GUI.Quit is called. Instead you need to understand how the Turing GUI module works. The loop that has GUI.ProcessEvent in it, will check to see if any buttons are pressed, update them, draw them, etc. The only way it returns true (and therefore exits the loop) is if the GUI has quit. When you press a button, the GUI module calls the procedure you give it when you made the button. The only way to know the button has been pressed is if that procedure has been called. So basically all you have to do, is increment i in your NextQ procedure.
nick4563




PostPosted: Mon Jan 17, 2011 9:32 pm   Post subject: RE:GUI button.... How to do an if GUI button pressed

OK i read the GUI module page and understand what you are saying now thank you my code now works great... Do you have any ideas on how to set restrictions sot hat a string variable can only be ye or no?
Tony




PostPosted: Mon Jan 17, 2011 10:25 pm   Post subject: RE:GUI button.... How to do an if GUI button pressed

code:

if my_string = "yes" or my_string = "no" then
   ...
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nick4563




PostPosted: Tue Jan 18, 2011 3:34 pm   Post subject: RE:GUI button.... How to do an if GUI button pressed

thanks got it
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: