I have a problem in If

Page 1 of 1

5 Replies - 585 Views - Last Post: 09 June 2009 - 08:52 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=109152&amp;s=2c42ed35c1cb0811276758a3bfbe4b62&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 tutumlu

Reputation: 0
• Posts: 2
• Joined: 05-June 09

I have a problem in If

Posted 09 June 2009 - 08:02 AM

I am 15 years old. I am from Turkey. I can speak very little English. I have just started programming. I am very new into this subject.

I have a problem in If

```
int sifre;
sifre = Convert.ToInt32(textBox2.Text);
{
label4.Text = "Başarılı..";
}
else
{
label4.Text = "Başarısız.";
}

```

Is This A Good Question/Topic? 0

Replies To: I have a problem in If

#2 RudiVisser

• .. does not guess solutions

Reputation: 1007
• Posts: 3,564
• Joined: 05-June 09

Re: I have a problem in If

Posted 09 June 2009 - 08:05 AM

Hmmmm.... What is the problem?

#3 tutumlu

Reputation: 0
• Posts: 2
• Joined: 05-June 09

Re: I have a problem in If

Posted 09 June 2009 - 08:27 AM

Then

I have error.

I hope , have understood ..

#4 RudiVisser

• .. does not guess solutions

Reputation: 1007
• Posts: 3,564
• Joined: 05-June 09

Re: I have a problem in If

Posted 09 June 2009 - 08:32 AM

"Erol" isn't a number, you would have to enter "123" into the text box to have your if() statement work.

Convert.ToInt32() won't work with something like "one", "two", etc. It needs to actually be a number.

You could also use Int32.Parse(textBox2.Text), I don't like using the Convert class for some reason

• MrCupOfT

Reputation: 2292
• Posts: 9,531
• Joined: 29-May 08

Re: I have a problem in If

Posted 09 June 2009 - 08:51 AM

tryparse would be better.

#6 eclipsed4utoo

Reputation: 1532
• Posts: 5,969
• Joined: 21-March 08

Re: I have a problem in If

Posted 09 June 2009 - 08:52 AM

```string ad;
int sifre;

if (!int.TryParse(textBox2.Text, out sifre))
{
MessageBox.Show("Enter a valid number");
return;
}

{
label4.Text = "Başarılı..";
}
else
{
label4.Text = "Başarısız.";
}

```