Results 1 to 3 of 3

Thread: If Statement

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2002
    Location
    Pilipinas
    Posts
    441

    If Statement

    I have a textBox1 in my C# project. How can i use the IF statement if the value of textBox1 is greater than or equal to 75, the remarks is "Passed" else "Failed".

    I used:

    int a;
    string remarks;

    a = int.Parse(textBox1.Text);

    If (a>=75) then
    remarks="Passed"
    Else
    remarks="Failed"
    End If

    Kindly correct this?

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    Code:
    a = Convert.ToInt16(textBox1.Text); 
    
    If (a>=75) 
        remarks="Passed" ;
    Else 
        remarks="Failed";
    End If

  3. #3
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Kovan? Your mixing up your VB.Net with C#....lol. Here is the correct way:
    Code:
    a = int.Parse(textBox1.Text); 
    
    if (a>=75) 
        remarks="Passed" ;
    else 
        remarks="Failed";
    That works if your if statement only processes one line of code. To process more than one line of code in an if block, you need to use the { } braces:
    Code:
    a = int.Parse(textBox1.Text); 
    
    if (a>=75) 
    {
        remarks="Passed" ;
        // use the braces if you have more than one line
        // being processed.
    }
    else 
    {
        remarks="Failed";
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width