Hi all
I am using the following VB6 code and I get this error Variable 'osv' is used before it has been assigned a value in VB2010.
I want to use this code/method for getting the version, I just want to fix this code:
Code:Public Class Form1 Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (lpVersionInformation As OSVERSIONINFO) As Long Private Structure OSVERSIONINFO Dim OSVSize As Integer Dim dwVerMajor As Integer Dim dwVerMinor As Integer Dim dwBuildNumber As Integer Dim PlatformID As Integer Dim szCSDVersion As String End Structure Private Const VER_PLATFORM_WIN32s = 0 Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32_NT = 2 ' Returns the version of Windows that the user is running Public Function GetWindowsVersion() As String Dim osv As OSVERSIONINFO osv = 0 osv.OSVSize = Len(OSVERSIONINFO) If GetVersionEx(osv) = 1 Then Select Case osv.PlatformID Case VER_PLATFORM_WIN32s GetWindowsVersion = "Win32s on Windows 3.1" Case VER_PLATFORM_WIN32_NT GetWindowsVersion = "Windows NT" Select Case osv.dwVerMajor Case 3 GetWindowsVersion = "Windows NT 3.5" Case 4 GetWindowsVersion = "Windows NT 4.0" Case 5 Select Case osv.dwVerMinor Case 0 GetWindowsVersion = "Windows 2000" Case 1 GetWindowsVersion = "Windows XP" Case 2 GetWindowsVersion = "Windows Server 2003" End Select Case 6 Select Case osv.dwVerMinor Case 0 GetWindowsVersion = "Windows Vista/Server 2008" Case 1 GetWindowsVersion = "Windows 7/Server 2008 R2" End Select End Select Case VER_PLATFORM_WIN32_WINDOWS Select Case osv.dwVerMinor Case 0 GetWindowsVersion = "Windows 95" Case 90 GetWindowsVersion = "Windows Me" Case Else GetWindowsVersion = "Windows 98" End Select End Select Else GetWindowsVersion = "Unable to identify your version of Windows." End If End Function Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load .... call GetWindowsVersion to show win version .... End Sub End Class




Reply With Quote