
This routine will require the declaration of the Windows API function GetVersion&(). It needs to be coded as in the following line:
For VB3/VB4-16:
Declare Function GetVersion& Lib "Kernel" ()
For VB4-32/VB5:
Declare Function GetVersion Lib "kernel32" Alias "GetVersion" () As Long
This routine will also require the creation of 3 module level functions: The first of the three functions is MakeNybble() which is a routine to convert a hexadecimal digit into its binary counterpart. The second of these functions is DecimalValue() which converts a binary byte into a decimal value. The final of these three functions is GetWindowsVersion() which manipulates the other two functions and returns the Windows version in use. Below are these three functions in their entirety.
Function MakeNybble (HexCharacter As String)
' This routine is called from the GetWindowsVersion routine
Select Case Left$(HexCharacter, 1)
Case "0": MakeNybble = "0000"
Case "1": MakeNybble = "0001"
Case "2": MakeNybble = "0010"
Case "3": MakeNybble = "0011"
Case "4": MakeNybble = "0100"
Case "5": MakeNybble = "0101"
Case "6": MakeNybble = "0110"
Case "7": MakeNybble = "0111"
Case "8": MakeNybble = "1000"
Case "9": MakeNybble = "1001"
Case "A": MakeNybble = "1010"
Case "B": MakeNybble = "1011"
Case "C": MakeNybble = "1100"
Case "D": MakeNybble = "1101"
Case "E": MakeNybble = "1110"
Case "F": MakeNybble = "1111"
End Select
End Function
Function DecimalValue (BinaryByte As String) As Integer
' This routine is called from the GetWindowsVersion routine
Dim x As Integer
Dim v As Integer
Dim TempVal As Integer
v = 128
For x = 1 To 8
If Mid$(BinaryByte, x, 1) = "1" Then TempVal = TempVal + v
v = v / 2
Next x
DecimalValue = TempVal
End Function
Function GetWindowsVersion () As String
' This routine also requires the following two functions:
' MakeNybble()
' DecimalValue()
Dim x As Long, y As String, z As Integer, t As String
Dim HN As String, LN As String
x = GetVersion()
x = x - 117440512 ' Don't need High Word returned for Windows version
t = Hex$(x) ' Make the numeric value a Hexadecimal string
y = Str$(Val(Right$(t, 2))) + "."' Hold the Major release # (ie 3.xx)
HN = MakeNybble(Left$(t, 1))
LN = MakeNybble(Mid$(t, 2, 1))
z = DecimalValue(HN + LN)
If z = 95 Then
GetWindowsVersion = "Windows 95"
Else
GetWindowsVersion = "Windows " + y + Trim$(Str$(z))
End If
End Function
Finally, you would call the Function and display its results as follows:
T = GetWindowsVersion() MsgBox T, 48, "Current Windows Version"Now please keep in mind that this routine was put together in great haste and there may likely be a more efficient means to accomplish this same task. If you know what it is - please let me know!