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

    If else statement Question

    Hello,

    I have been trying to get this to work for a while now and just to new to fully understand what is the problem.

    I'm using a OS class, that I found on the internet.
    Code:
    static public SoftwareArchitecture ProgramBits
            {
                get
                {
                    SoftwareArchitecture pbits = SoftwareArchitecture.Unknown;
    
                    System.Collections.IDictionary test = Environment.GetEnvironmentVariables();
    
                    switch (IntPtr.Size * 8)
                    {
                        case 64:
                            pbits = SoftwareArchitecture.Bit64;
                            break;
    
                        case 32:
                            pbits = SoftwareArchitecture.Bit32;
                            break;
    
                        default:
                            pbits = SoftwareArchitecture.Unknown;
                            break;
                    }
    
                    return pbits;
    What I do not understand is what I need to do to make this If else statement work with this above code.

    Code:
    private void button2_Click(object sender, EventArgs e)
            {
                if (OSVersionInfo.OSBits == 64)
    
                {
                    MessageBox.Show("OS is x64 Bit");
                }
                else if (OSVersionInfo.OSBits == 32)
                {
                    MessageBox.Show("OS is x86 Bit");
                }
                else
                {
                     //return 2;
                }
            }
    This is the error message that I get when I use 64 and 32.

    When I Debug, this is the error message that I get "Error 1 Operator '==' cannot be applied to operands of type 'JCS.OSVersionInfo.SoftwareArchitecture' and 'int' D:\OSVersionInfo\OSVersionInfo\Form1.cs 45 17 OSVersionInfo
    "

    This is the error message that I get when I switch it to Bit64 and Bit32

    Error 1 The name 'Bit64' does not exist in the current context D:\OSVersionInfo\OSVersionInfo\Form1.cs 45 41 OSVersionInfo


    Any help to learn what I'm doing wrong would be great.

    Thanks,

    -Mike

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: If else statement Question

    What type is the property OSBits. If it isn't an integer like the values 32 and 64 can be then you will see the compiler error you are seeing. To find out what type it is, put your mouse over the .OSBits property, right-click and choose "go to declaration".

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