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

Username:   Password: 
 RegisterRegister   
 Is it possible to make a button that when clicked the program exits, and how can it be done?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
skillspeed




PostPosted: Wed Jan 18, 2012 5:01 pm   Post subject: Is it possible to make a button that when clicked the program exits, and how can it be done?

What is it you are trying to achieve?
<Replace all the <> with your answers/code and remove the <>>
I have an isp and I am trying to make a button that when clicked exits the program, what the program is doesent matter I just need the program to exit when the button is clicked.

What is the problem you are having?
<Answer Here>
I am not sure how you go about doing this, I dont know if there is a command that does this, etcDescribe what you have tried to solve this problem
<Answer Here>


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

This is all I know about making buttons:


var x, y, bnum, bud : int

drawfillbox ( 100, 280, 200, 310, 4)
drawfillbox ( 100, 240, 200, 270, 2)
drawfillbox (100, 200, 200, 230, 1)

if x >= 100 and x <= 200 and y >= 280 and y <= 310 then
colour ( 4)
put "You clicked the red box"

elsif x >= 100 and x <= 200 and y >= 240 and y <= 270 then
colour (2)
put "You clicked the green box"

elsif x >= 100 and x <= 200 and y >= 200 and y <= 230 then
colour (1)
put "You clicked the blue box"

else
colour (4)
put "Tsk tsk. You did not click inside a box."
end if

Turing:


<Add your code here>





Please specify what version of Turing you are using
<Answer Here>
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Wed Jan 18, 2012 6:16 pm   Post subject: Re: Is it possible to make a button that when clicked the program exits, and how can it be done?

I'm not sure what exactly you mean by exit, but I would suggest you read the documentation for Window.Close and return. They might help you accomplish what you want.

If the behavior you wanted was that of Window.Close, remember that the default Turing window's id is "defWinId".
Insectoid




PostPosted: Wed Jan 18, 2012 6:36 pm   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

'exiting a program' really just means there's no more code to execute. So the question becomes, if the button is clicked, how do I skip the rest of the code?
Zren




PostPosted: Wed Jan 18, 2012 6:53 pm   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

I assume you've looked into Mouse.Where, but as you didn't put it in your code...

You also need to be constantly checking, not just once.
Velocity




PostPosted: Wed Jan 18, 2012 9:04 pm   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

look up GUI.QUIT
Raknarg




PostPosted: Thu Jan 19, 2012 10:56 am   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

He's using Mouse.Where buttons, not GUI.
tg851




PostPosted: Thu Jan 19, 2012 11:18 am   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

a way to just quit the program,with custom error quit text is "Error.Halt("message here")"
very useful for various things
Beastinonyou




PostPosted: Thu Jan 19, 2012 1:17 pm   Post subject: Re: Is it possible to make a button that when clicked the program exits, and how can it be done?

Turing:

var window : int := Window.Open ("graphics: 200;200")
var exitButton : boolean := false
loop
     % Do Stuff
     % If you clicked inside the exit button
     if mouseX >= exitX and mouseX <= exitX + 20 and mouseY >= exitY and mouseY <= exitY + 20 and mouseClicked= 1 then
          exitButton := true
     end if
     exit when exitButton = true
end loop
Window.Close (window)


You could approach this by using a boolean, so when the user clicks that button, the boolean becomes true, and will exit the main loop. You could then close the window manually
Sponsor
Sponsor
Sponsor
sponsor
turinghelp101




PostPosted: Thu Jan 19, 2012 4:51 pm   Post subject: Re: Is it possible to make a button that when clicked the program exits, and how can it be done?

Beastinonyou @ Thu Jan 19, 2012 1:17 pm wrote:
Turing:

var window : int := Window.Open ("graphics: 200;200")
var exitButton : boolean := false
loop
     % Do Stuff
     % If you clicked inside the exit button
     if mouseX >= exitX and mouseX <= exitX + 20 and mouseY >= exitY and mouseY <= exitY + 20 and mouseClicked= 1 then
          exitButton := true
     end if
     exit when exitButton = true
end loop
Window.Close (window)


You could approach this by using a boolean, so when the user clicks that button, the boolean becomes true, and will exit the main loop. You could then close the window manually


I think this is what the guy was asking:

Instead of having to click manually to close the window, he wants a button that when clicked on closes the window
turinghelp101




PostPosted: Thu Jan 19, 2012 4:57 pm   Post subject: Re: Is it possible to make a button that when clicked the program exits, and how can it be done?

I found this in a turing reference, this should help you:



import GUI


const screenWidth : int := Config.Display (cdScreenWidth)
const screenHeight : int := Config.Display (cdScreenHeight)
const titleBarHeight : int := 32
const windowEdgeSize : int := 13
const windowWidth : int := 150
const windowHeight : int := 100
var windowID, windowNumber, closeButton, quitButton : int := 0

procedure CloseAndOpen
if windowID not= 0 then
GUI.CloseWindow (windowID)
end if
windowNumber += 1
var xPos : int := Rand.Int (0, screenWidth - windowWidth -
windowEdgeSize)
var yPos : int := Rand.Int (0, screenHeight - windowHeight -
titleBarHeight)
windowID := Window.Open ("title:Window #" +
intstr (windowNumber) + ",graphics:" +
intstr (windowWidth) + ";" + intstr (windowHeight) +
",position:" + intstr (xPos) + ";" + intstr (yPos))
closeButton := GUI.CreateButton (10, 60, 130,
"Close And Open", CloseAndOpen)
quitButton := GUI.CreateButton (10, 10, 130, "Quit", GUI.Quit)
end CloseAndOpen

CloseAndOpen
loop
exit when GUI.ProcessEvent
end loop
GUI.CloseWindow (windowID)
Alex C.




PostPosted: Thu Jan 19, 2012 5:14 pm   Post subject: RE:Is it possible to make a button that when clicked the program exits, and how can it be done?

GAAAAAAHHHHHHH! use code tags for the love of god!!! >Sad
chipanpriest




PostPosted: Fri Jan 20, 2012 12:30 pm   Post subject: Re: Is it possible to make a button that when clicked the program exits, and how can it be done?

Beastinonyou @ Thu Jan 19, 2012 1:17 pm wrote:
Turing:

var window : int := Window.Open ("graphics: 200;200")
var exitButton : boolean := false
loop
     % Do Stuff
     % If you clicked inside the exit button
     if mouseX >= exitX and mouseX <= exitX + 20 and mouseY >= exitY and mouseY <= exitY + 20 and mouseClicked= 1 then
          exitButton := true
     end if
     exit when exitButton = true
end loop
Window.Close (window)



You don't need a boolean value. Just tell the loop to exit. For example:
Turing:

var window : int := Window.Open ("graphics: 200;200")
loop
     % Do Stuff
     % If you clicked inside the exit button
     if mouseX >= exitX and mouseX <= exitX + 20 and mouseY >= exitY and mouseY <= exitY + 20 and mouseClicked= 1 then
         exit
     end if
end loop
Window.Close (window)
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  [ 12 Posts ]
Jump to:   


Style:  
Search: