-
December 19th, 2008, 12:56 PM
#1
Button functions
Hi Everyone
Basically I have created a music programme and need a button (Demo) that when pressed displays various notes and text in an edit box. This part I can do. However I need to, if it is possible, to be able to press the button again and this time it would display another set of notes/text. So basically how do you go about giving a button a multipurpose function
many thanks
Darren
-
December 19th, 2008, 01:01 PM
#2
Re: Button functions
Well, you can do it in various ways. The idea is that you should keep track of the state.
For instance, suppose m_showSet1 is a bool variable, member of the class.
Code:
void CYourDialog::OnButton()
{
if(m_showSet1)
{
// show the first set
}
else
{
// show the second set
}
m_showSet1 = !m_showSet1;
}
If you need to show more sets, you can adapt this, using an int instead of bool, or an enum. I hope you figured the idea.
-
December 19th, 2008, 01:07 PM
#3
Re: Button functions
Originally Posted by cilu
Well, you can do it in various ways. The idea is that you should keep track of the state.
For instance, suppose m_showSet1 is a bool variable, member of the class.
Code:
void CYourDialog::OnButton()
{
if(m_showSet1)
{
// show the first set
}
else
{
// show the second set
}
m_showSet1 = !m_showSet1;
}
If you need to show more sets, you can adapt this, using an int instead of bool, or an enum. I hope you figured the idea.
So if I wanted about 4 different options I would use int? would I use just one or would you need 4 of these? Also after the 4 if it was presses a 5th time how would you set it to go back to click 1 ( the first demo )
thanks
-
December 19th, 2008, 01:11 PM
#4
Re: Button functions
Well, Why not thinking a little bit for yourself? Think sequences: 0, 1, 2, 3, 4, 0, 1, 2, 3, 4... Does that ring any bells?
-
December 19th, 2008, 01:25 PM
#5
Re: Button functions
If you want different contents at different clicks, why can't you consider (rand() % UB); Where 'UB' is the upper bound.
-
December 19th, 2008, 01:27 PM
#6
Re: Button functions
sort of. I am VERY new to C++. Only been using it for a few weeks, so all is very foreign to me. So any specfic help from anyone would be greatfully received
Darren
-
December 19th, 2008, 01:38 PM
#7
Re: Button functions
Originally Posted by cilu
Well, Why not thinking a little bit for yourself? Think sequences: 0, 1, 2, 3, 4, 0, 1, 2, 3, 4... Does that ring any bells?
Classic Waltz for a Mayan Indain????
[The Olmec and Maya civilization used zero as a separate number as early as 1st century BC]
TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
2008, 2009,2010
In theory, there is no difference between theory and practice; in practice there is.
* Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
* How NOT to post a question here
* Of course you read this carefully before you posted
* Need homework help? Read this first
-
December 19th, 2008, 01:39 PM
#8
Re: Button functions
Code:
switch(rand() % 5)
{
case 1: //// show the first set
break;
case 2: //// show the second set
break;
case 3: //// show the fourth set
break;
case4: //// show the fourth set
break;
}
-
December 19th, 2008, 01:41 PM
#9
Re: Button functions
Originally Posted by unnamed
Code:
switch(rand() % 5)
{
case 1: //// show the first set
break;
case 2: //// show the second set
break;
case 3: //// show the fourth set
break;
case4: //// show the fourth set
break;
}
This does make more sense but how does one g oabout making a button have a switch statement?
-
December 19th, 2008, 01:49 PM
#10
Re: Button functions
The button doesn't have a switch statement. But the button click event has a handler. You put the switch in the handler. Do you know how to create that?
-
December 19th, 2008, 01:54 PM
#11
Re: Button functions
Originally Posted by cilu
The button doesn't have a switch statement. But the button click event has a handler. You put the switch in the handler. Do you know how to create that?
um no not really...please do explain.....sorruy this must be very annoying...but like I said I am still getting used to it all.
-
December 19th, 2008, 02:16 PM
#12
Re: Button functions
Double click on the button and an event handler will be created by the Visual Studio.
-
December 19th, 2008, 02:26 PM
#13
Re: Button functions
void CU6b82Dlg::OnDemo()
{
switch(rand() % 5)
{
case 1: m_Sequence="BBB";
break;
case 2: m_Sequence="AAA";
break;
case 3: m_Sequence="CDEF";
break;
case 4: m_Sequence="abcde";
break;
}
}
I have done this...However it doesnt work..does the 'switch(rand() % 5)' have to be changed?
-
December 19th, 2008, 03:07 PM
#14
Re: Button functions
Well, what should happen? What doesn't work? In this function you are setting the value of a variable, m_Sequence? Where is it supposed to be used? You you want to show it's content somewhere? You have to explain that.
-
December 19th, 2008, 03:17 PM
#15
Re: Button functions
basically i have 4 edit boxes. When I press demo I want the text i preset in the function to appear. For example clicked once i may wish for ABCD to appear in edit box one (m_Sequence).Then pressed again I may want DACB to appear in edit box one (m_Sequence) and DEFG in edit box two (m_Sequence2)...and so on
this make sense?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|