Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange if statement behaviour...

Status
Not open for further replies.

Raenius

Programmer
Oct 14, 2003
77
0
0
NL
Hi all,

On the load of a windows form I run some quesries against a database and extract some fields. For example if a certain settings is to be enabeled or not.

If you look at the following code:

Code:
		 // Audio Tab Page settings
		string msg2 ="Audio_enabled: " +audio_en;
		MessageBox.Show(msg2);
		if(audio_en.ToString() == "yes")
			{
			this.checkBoxEditRouterAudioYes.Checked = true;
			}
		else
			{
			MessageBox.Show("why?");
			this.checkBoxEditRouterAudioNo.Checked = true;
			}

The messagebox first says Audio Enabled: yes and then it STILL goes in the ELSE clause displaying a messagebox with the words: Why?

Does anyone have a clue what is going on here?

Thanks in advance...

- Raenius

"Free will...is an illusion"
 
Have you tried using the .Equals(string) method to do your string comparison, rather than the == operator?
 
or have you tried trimming any padding spaces out of audio_en?
 
i would imagine its a padding issue but without seeing if those if / else statements are in a larger if / else nest its hard to tell

Skute

"There are 10 types of people in this World, those that understand binary, and those that don't!"
 
Equals method still gives the same result.

Trimming the Padding I am now trying..

Basically what happens before this is that an query is made to a database and the string audio_en is declared via the sqldatareader..


"Free will...is an illusion"
 
And indeed it was a trailing spaces issue, very weird because I thought that I had excluded this in my database updates...strange..

No worries everything is working fine now... up to my new part of the program which is Email validation with a regex in a textbox...

Thanks for the help!

- Raenius

"Free will...is an illusion"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top