CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2012
    Posts
    36

    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
    Fox Lake, IL
    Posts
    15,007

    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 / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    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
    36

    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
  •  





Click Here to Expand Forum to Full Width

Featured