need help with a VB.NET in C#

i have a VB.NET code id love to use in C# i tried useing a converter

Page 1 of 1

12 Replies - 1293 Views - Last Post: 28 May 2010 - 05:46 AM Rate Topic: -----

#1 NightsEvil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 85
  • Joined: 23-May 10

need help with a VB.NET in C#

Posted 28 May 2010 - 02:21 AM

i have this VB code i LOVE and i tried to use a converter on it but it didnt seem to do the trick and id love to be able to use it in my C# application any help please?

Dim os = Environment.OSVersion.Version
If os.Major = 6 AndAlso os.Minor = 1 Then
MessageBox.Show("Running Windows 7")
ElseIf os.Major = 6 AndAlso os.Minor = 0 Then
MessageBox.Show("Running Vista")
ElseIf os.Major = 5 AndAlso os.Minor = 1 Then
MessageBox.Show("Running XP")
Else
MessageBox.Show("Unspecified OS")
End If


Is This A Good Question/Topic? 0
  • +

Replies To: need help with a VB.NET in C#

#2 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 03:39 AM

Peace of cake! :-)

private void DoSomething()
{
    var os = Environment.OSVersion.Version;
    if (os.Major == 6 && os.Minor == 1)
    {
        MessageBox.Show("Running Windows 7");
    }
    else if (os.Major == 6 && os.Minor == 0)
    {
        MessageBox.Show("Runnine Vista");
    }
    else if (os.Major == 5 && os.Minor == 1)
    {
        MessageBox.Show("Running XP");
    }
    else
    {
        MessageBox.Show("Unspecified OS");
    }
}


Was This Post Helpful? 1
  • +
  • -

#3 NightsEvil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 85
  • Joined: 23-May 10

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 04:10 AM

well i get errors like:

"does not contain a definition for 'Major' and no extension method 'Major' accepting a first argument of type 'WindowsFormsApplication1.var' could be found (are you missing a using directive or an assembly reference?)"

and:

"does not contain a definition for 'Minor' and no extension method 'Minor' accepting a first argument of type 'WindowsFormsApplication1.var' could be found (are you missing a using directive or an assembly reference?)"

but they go away when i "Generate a Property stub" for "major" and "minor" but i still get this error:

"Cannot implicitly convert type 'System.Version'"

for"
Environment.OSVersion.Version;

Was This Post Helpful? 0
  • +
  • -

#4 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 04:26 AM

Could you post your code... It would be easier to help you...
Was This Post Helpful? 0
  • +
  • -

#5 NightsEvil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 85
  • Joined: 23-May 10

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:20 AM

not sure what more i can give you? is this what you need? the error are with the "Environment.OSVersion.Version;"
        private void Services_Click(object sender, EventArgs e)
        {
             var os = Environment.OSVersion.Version;
    if (os.Major == 6 && os.Minor == 1)
    {
        MessageBox.Show("Running Windows 7");
    }
    else if (os.Major == 6 && os.Minor == 0)
    {
        MessageBox.Show("Runnine Vista");
    }
    else if (os.Major == 5 && os.Minor == 1)
    {
        MessageBox.Show("Running XP");
    }
    else
    {
        MessageBox.Show("Unspecified OS");
    }
}

Was This Post Helpful? 0
  • +
  • -

#6 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:28 AM

This code works perfectly... What version of Visual Studio you are using (2005,2008,2010)? Which framework you are using (2.0, 3.5 or 4.0). Do you have the using System; statement at the top of your class?
Was This Post Helpful? 0
  • +
  • -

#7 NightsEvil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 85
  • Joined: 23-May 10

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:31 AM

im using visual studio 2010 express, and target framework is 2.0, am i missing any references maybe? and yes i have using System; at the top infact if it will help i have all of these:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
Was This Post Helpful? 0
  • +
  • -

#8 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:34 AM

What version of C# are you using? Your first error message makes me think it's pre 3.0. Ignore this, see my post below. You posed while I was writing :)

This post has been edited by Momerath: 28 May 2010 - 05:36 AM

Was This Post Helpful? 0
  • +
  • -

#9 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:35 AM

Does this issue remain if you target the .NET 4.0 or 3.5 Framework?
Was This Post Helpful? 0
  • +
  • -

#10 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1012
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:35 AM

View PostNightsEvil, on 28 May 2010 - 03:31 AM, said:

im using visual studio 2010 express, and target framework is 2.0,

That's your problem. 'var' didn't exist pre version 3.0 (and personally, I don't recomend using var unless you are doing something with Linq, use the explicit type!).

Change the 'var' to 'Environment'.
Was This Post Helpful? 1
  • +
  • -

#11 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:36 AM

Actually change the var to Version.
Was This Post Helpful? 1
  • +
  • -

#12 NightsEvil  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 85
  • Joined: 23-May 10

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:41 AM

i tried bumping it up to target framework 4.0 and adding using System.Linq; but same error

changing var to Version fixed it perfectly thank you very much! by the way.. totally off topic (sorry) but whats the advantages of VS 2010 pro over express?
Was This Post Helpful? 0
  • +
  • -

#13 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: need help with a VB.NET in C#

Posted 28 May 2010 - 05:46 AM

In Pro version you're able to create any type of project (Windows Forms, Web,... etc...) and in any language (C#, VB.NET,... etc...). There might be some other advantages I don't know about, since I've always used only PRO versions.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1