If else statement Question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: If else statement Question

  1. #1
    Join Date
    May 2012
    Posts
    34

    If else statement Question

    Hello,

    I'm trying to figure out how to make this work. I do not know what would be a better fit to help me with this code.


    if (OSVersionInfo.ServicePack != string.Empty)
    //sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
    label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
    label30.BackColor = Color.White;
    label30.ForeColor = Color.Green;
    else
    //sb.AppendLine("Service Pack = None");
    label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
    label30.BackColor = Color.White;
    label30.ForeColor = Color.Green;

    I need to be able to only check for 1 condition, but once found, exeute the code with 3 lines.

    If I cannot do it with the If Else code, can you please point me in the write direction.

    Thanks,

  2. #2
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,999

    Re: If else statement Question

    Dim a Flag as Boolean. Set it to FALSE. Check the condition, and run the code (which would add the Version)
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Arjay's Avatar
    Arjay is offline Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    11,419

    Re: If else statement Question

    If you are coding in C#, you need to add braces around the if and else statements.

    Code:
    if (OSVersionInfo.ServicePack != string.Empty)
    {
      //sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
      label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
      label30.BackColor = Color.White;
      label30.ForeColor = Color.Green;
    } 
    else
    {
       //sb.AppendLine("Service Pack = None");
       label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
       label30.BackColor = Color.White;
       label30.ForeColor = Color.Green;
    }

  4. #4
    Join Date
    May 2012
    Posts
    34

    Re: If else statement Question

    Thanks Arjay,

    That helped me.

    Mike


    Quote Originally Posted by Arjay View Post
    If you are coding in C#, you need to add braces around the if and else statements.

    Code:
    if (OSVersionInfo.ServicePack != string.Empty)
    {
      //sb.AppendLine(String.Format("Service Pack = {0}", OSVersionInfo.ServicePack));
      label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
      label30.BackColor = Color.White;
      label30.ForeColor = Color.Green;
    } 
    else
    {
       //sb.AppendLine("Service Pack = None");
       label30.Text = String.Format("Service Pack = {0}", OSVersionInfo.VersionString);
       label30.BackColor = Color.White;
       label30.ForeColor = Color.Green;
    }

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center