#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2012
    Location
    Wisconsin
    Posts
    1
    Rep Power
    0

    Wish to convert Win32_Keyboard layout string to decimal


    I have a vb script that reads the keyboard information. The layout field returns a string of "00000409" for US. The software that I deal with can be in many different languages. I wish to be able to create a function that returns a different string based on the passed in string.

    I have attempted this functionality first:


    Set objShell = WScript.CreateObject("WScript.Shell")
    Function KeyboardLanguage(strID)
    Wscript.Echo strID
    Select Case strID
    Case "00000402"
    KeyboardLanguage = "Bulgarian"
    Case "00000404"
    KeyboardLanguage = "Chinese (Traditional) - US Keyboard"
    Case "00000405"
    KeyboardLanguage = "Czech"
    Case "00000406"
    KeyboardLanguage = "Danish"
    Case "00000407"
    KeyboardLanguage = "German"
    ... until I get to
    Case "0000040a"

    It failed here, so I tried to take the hex value of these strings

    Case 1026 '00000402
    KeyboardLanguage = "Bulgarian"
    Case 1028 '00000404
    KeyboardLanguage = "Chinese (Traditional) - US Keyboard"
    Case 1029 '00000405
    KeyboardLanguage = "Czech"
    Case 1030 '00000406
    KeyboardLanguage = "Danish"
    Case 1031 '00000407
    KeyboardLanguage = "German"

    I think that I need to convert the string to hex, and have searched via Google and tried some convert functions, but none seem to work.

    Would someone have an answer to my issue?

    Thank you.
  2. #2
  3. Type Cast Exception
    Devshed Supreme Being (6500+ posts)

    Join Date
    Apr 2004
    Location
    OAKLAND CA | Adam's Point (Fairyland)
    Posts
    14,954
    Rep Power
    8617
    If you're trying to get your hex string to an integer then doing Val() on the string with &H prepended to it will do this in most VB flavors (there are other converters but this always worked when I tried it, pre-.Net anyway)

    Code:
    Sub ExampleHex()
        strID = "00000409"
        lngvalue = Val("&H" & strID)
        MsgBox strid & " = " & lngvalue
    End Sub
    So your "00000409" evaluates to 1033
    medialint.com

    “Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

IMN logo majestic logo threadwatch logo seochat tools logo