Get Country

  • VB.NET

Es gibt 9 Antworten in diesem Thema. Der letzte Beitrag () ist von ErfinderDesRades.

    Get Country

    Hm,

    das ist komisch.
    Mit diesem Code lese ich das Land aus, das an dem PC eingestellt ist:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Public Class Form1
    3. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    4. MsgBox((GetInfo(LOCALE_SENGCOUNTRY)))
    5. End Sub
    6. <DllImport("kernel32.dll")> _
    7. Private Shared Function GetLocaleInfo(ByVal Locale As UInteger, ByVal LCType As UInteger, <Out()> ByVal lpLCData As System.Text.StringBuilder, ByVal cchData As Integer) As Integer
    8. End Function
    9. Private Const LOCALE_SYSTEM_DEFAULT As UInteger = &H400
    10. Private Const LOCALE_SENGCOUNTRY As UInteger = &H1002
    11. Private Shared Function GetInfo(ByVal lInfo As UInteger) As String
    12. Dim lpLCData = New System.Text.StringBuilder(256)
    13. Dim ret As Integer = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, lInfo, lpLCData, lpLCData.Capacity)
    14. If ret > 0 Then
    15. Return lpLCData.ToString().Substring(0, ret - 1)
    16. End If
    17. Return String.Empty
    18. End Function
    19. Public Shared Function GetLetters()
    20. Dim MyCountry As String = (GetInfo(LOCALE_SENGCOUNTRY))
    21. Return MyCountry
    22. End Function
    23. End Class


    Funktioniert wunderbar.
    Wenn ich das allerdings in einer Console-Anwendung machen möchte:

    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Runtime.InteropServices
    2. Module Module1
    3. Sub Main()
    4. WriteLine(GetInfo(LOCALE_SENGCOUNTRY))
    5. End Sub
    6. <DllImport("kernel32.dll")> _
    7. Private Function GetLocaleInfo(ByVal Locale As UInteger, ByVal LCType As UInteger, <Out()> ByVal lpLCData As System.Text.StringBuilder, ByVal cchData As Integer) As Integer
    8. End Function
    9. Private Const LOCALE_SYSTEM_DEFAULT As UInteger = &H400
    10. Private Const LOCALE_SENGCOUNTRY As UInteger = &H1002
    11. Private Function GetInfo(ByVal lInfo As UInteger) As String
    12. Dim lpLCData = New System.Text.StringBuilder(256)
    13. Dim ret As Integer = GetLocaleInfo(LOCALE_SYSTEM_DEFAULT, lInfo, lpLCData, lpLCData.Capacity)
    14. If ret > 0 Then
    15. Return lpLCData.ToString().Substring(0, ret - 1)
    16. End If
    17. Return String.Empty
    18. End Function
    19. Public Function GetLetters()
    20. Dim MyCountry As String = (GetInfo(LOCALE_SENGCOUNTRY))
    21. Return MyCountry
    22. End Function
    23. End Module


    Dann krieg ich den Fehler:

    Ungültige Konvertierung von der Zeichenfolge Germany in Typ Integer.

    Woran liegt das?
    C# Developer
    Learning C++
    Da krieg ich aber den gleichen Fehler:

    VB.NET-Quellcode

    1. Sub Main()
    2. WriteLine(System.Globalization.CultureInfo.CurrentCulture.DisplayName)
    3. End Sub


    Ungültige Konvertierung von der Zeichenfolge Deutsch (Deutschland) in Typ Integer.
    C# Developer
    Learning C++
    Integer = Zahl
    Deutschland = String = Text

    Klar das das nicht geht.
    Bilder
    • Unbenannt.png

      8,48 kB, 712×90, 137 mal angesehen
    There is no CLOUD - just other people's computers

    Q: Why do JAVA developers wear glasses?
    A: Because they can't C#

    Daily prayer:
    "Dear Lord, grand me the strength not to kill any stupid people today and please grant me the ability to punch them in the face over standard TCP/IP."