473,386 Members | 1,823 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

compare string to button text

I am using visual c++ 2003 i believe.

I created a new win32 application, and put 1 button on the form and
changed it's text to "Start".
and this code does not work:
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
if (button1->Text == "Start")
{
button1->Text = "Stop";
}
else
{
button1->Text == "Start";
}
}
the project compiles ok, but when the code executes, the if statement
always goes to the else clause. The text on the button is "Start"
though. I think I am not understanding some fundamental concepts
with
pointers/objects....
Mar 27 '08 #1
4 1018
Demosthenes wrote:
I am using visual c++ 2003 i believe.

I created a new win32 application, and put 1 button on the form and
changed it's text to "Start".
and this code does not work:
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
if (button1->Text == "Start")
{
button1->Text = "Stop";
}
else
{
button1->Text == "Start";
}
}
the project compiles ok, but when the code executes, the if statement
always goes to the else clause. The text on the button is "Start"
though. I think I am not understanding some fundamental concepts
with
pointers/objects....
When comparing add S prefix to your literals:

if (button1->Text == S"Start")
...
else
...

Take a look to:

http://www.codeproject.com/KB/mcpp/managed_types.aspx
http://punkouter.wordpress.com/2007/...y-reference-ob
jects-equality/
Regards
--
Cholo Lennon
Bs.As.
ARG

Mar 27 '08 #2
Cholo Lennon wrote:
Demosthenes wrote:
>I am using visual c++ 2003 i believe.

I created a new win32 application, and put 1 button on the form and
changed it's text to "Start".
and this code does not work:
private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)
{
if (button1->Text == "Start")
{
button1->Text = "Stop";
}
else
{
button1->Text == "Start";
}
}
the project compiles ok, but when the code executes, the if statement
always goes to the else clause. The text on the button is "Start"
though. I think I am not understanding some fundamental concepts
with
pointers/objects....

When comparing add S prefix to your literals:

if (button1->Text == S"Start")
or even better,

if (button1->Text->Equals(S"Start"))

This makes it clear it is not pointer comparison.
...
else
...

Take a look to:

http://www.codeproject.com/KB/mcpp/managed_types.aspx
http://punkouter.wordpress.com/2007/...y-reference-ob
jects-equality/
Regards

Mar 27 '08 #3
On Mar 27, 5:14*pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:
Cholo Lennon wrote:
Demostheneswrote:
I am using visual c++ 2003 i believe.
I created a new win32 application, and put 1 button on the form and
changed it's text to "Start".
and this code does not work:
private: System::Void button1_Click(System::Object * *sender,
System::EventArgs * *e)
* * {
* * * * * *if (button1->Text == "Start")
* * * * {
* * * * * button1->Text = "Stop";
* * * * * * }
* * * else
* * * * {
* * * * * button1->Text == "Start";
* * * * *}
* * }
the project compiles ok, but when the code executes, the if statement
always goes to the else clause. *The text on the button is "Start"
though. *I think I am not understanding some fundamental concepts
with
pointers/objects....
When comparing add S prefix to your literals:
if (button1->Text == S"Start")

or even better,

if (button1->Text->Equals(S"Start"))

This makes it clear it is not pointer comparison.
* * * *...
else
* * * *...
Take a look to:
http://www.codeproject.com/KB/mcpp/managed_types.aspx
http://punkouter.wordpress.com/2007/...ing-equality-r...
jects-equality/
Regards- Hide quoted text -

- Show quoted text -- Hide quoted text -

- Show quoted text -
thanks guys, now i run into a strange thing here, the first time i
press the button, the buttons text = start, and gets set to stop.
Then from stop to start, then it never works again. here is my code

if (button1->Text == S"Start")
{
button1->Text = "Stop";
}
else
{
button1->Text = "Start";
}

Mar 28 '08 #4
On Mar 28, 9:37*am, Demosthenes <sadbastur...@yahoo.comwrote:
On Mar 27, 5:14*pm, "Ben Voigt [C++ MVP]" <r...@nospam.nospamwrote:


Cholo Lennon wrote:
>Demostheneswrote:
>I am using visual c++ 2003 i believe.
>I created a new win32 application, and put 1 button on the form and
>changed it's text to "Start".
>and this code does not work:
>private: System::Void button1_Click(System::Object * *sender,
>System::EventArgs * *e)
>* * {
>* * * * * *if (button1->Text == "Start")
>* * * * {
>* * * * * button1->Text = "Stop";
>* * * * * * }
>* * * else
>* * * * {
>* * * * * button1->Text == "Start";
>* * * * *}
>* * }
>the project compiles ok, but when the code executes, the if statement
>always goes to the else clause. *The text on the button is "Start"
>though. *I think I am not understanding some fundamental concepts
>with
>pointers/objects....
When comparing add S prefix to your literals:
if (button1->Text == S"Start")
or even better,
if (button1->Text->Equals(S"Start"))
This makes it clear it is not pointer comparison.
* * * *...
else
* * * *...
Take a look to:
>http://www.codeproject.com/KB/mcpp/managed_types.aspx
>http://punkouter.wordpress.com/2007/...ing-equality-r....
jects-equality/
Regards- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -

thanks guys, now i run into a strange thing here, the first time i
press the button, the buttons text = start, and gets set to stop.
Then from stop to start, then it never works again. *here is my code

* * *if (button1->Text == S"Start")
* * * * {
* * * * * button1->Text = "Stop";
* * * * }
* * * else
* * * * {
* * * * * button1->Text = "Start";
* * * * }- Hide quoted text -

- Show quoted text -
but this seems to work fine:

if (button1->Text->Equals(S"Start"))
{
button1->Text = "Stop";
timer1->Enabled = true;
timer1->Start;
}
else
{
button1->Text = "Start";
timer1->Stop;
timer1->Enabled = false;
}
Mar 28 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
4
by: Matt | last post by:
I posted this problem before but no reply. Now I repost again. I want to compare the address number in javascript, and the address number is alphanumeric. I have a text box and the user needs to...
0
by: TN Bella | last post by:
Hi, I am trying to get my compare validator to fire properly...Since I have panels the validator wouldn't work properly, the app would fire right but would insert the data regardless and the...
3
by: Peter | last post by:
ASP.NET 1.1, this is a Intranet application and runs only on IE. I have two webform text boxes which contain dates - starting date and ending date. The dates could be in any format. for...
3
by: Twinkle | last post by:
HI there i want to compare between two strings char by char.every strings having a word document.first string name is strFileName and second string name is strFilename1. i want to compare...
2
by: Twinkle | last post by:
HI guy I am using This Code For Compare Two Files at Button Click Event. if user select Data from richtextbox1 and click the Compare Button then it will match with second richtextbox2 data. this...
0
by: Michael Jenck | last post by:
Hi All, I have been playing with the codedom and can't get it to output for option compare Binary with a CodeCompileUnit. I have searched the web and Don't now if it's possible. If it's not...
3
by: kibong | last post by:
I am trying to get what the user inputs into the box and then take that to check their answers and make sure everything is correct before moving on. here is my code <%@ Page Language="vb" %> ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.