如何在 Visual Basic 6.0 应用程序中设置区域选项?

发布于 2024-08-28 13:11:21 字数 137 浏览 9 评论 0原文

我现在有一个处于生产环境中的VB6应用程序,该应用程序正在读取电脑的区域设置;但现在,我需要为应用程序设置另一个区域设置,而不更改电脑的设置。

如何在全球范围内设置新的区域设置以将影响降至最低?有没有任何配置方法(或类似的方法)可以做到这一点?

I have a VB6's Application that is in production environment right now, this application is reading the pc's Regional Settings; but now, I need to set another Regional Settings for the application without change the pc's settings.

How can I set the new Regional Settings globally with the lowest impact? Is there any configuration method (or something like that) for do it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

睫毛上残留的泪 2024-09-04 13:11:21

来自 http://www.experts-exchange.com/Programming/Languages /Visual_Basic/Q_21841979.html

Option Explicit

Public Enum DateOrderEnum
   doDefault 'Your locale setting
   doMDY     'Month-Day-Year (U.S.)
   doDMY     'Day-Month-Year (EU, S.A.)
   doYMD     'Year-Month-Day (Japan)
End Enum

Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_STHOUSAND As Long = &HF
Public Const LOCALE_SDECIMAL  As Long = &HE

Public Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetLocaleInfoA Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Public Function GetThousandsSep() As String
   GetThousandsSep = pfGLI(GetUserDefaultLCID(), LOCALE_STHOUSAND)
End Function

Public Function GetDecimalSep() As String
   GetDecimalSep = pfGLI(GetUserDefaultLCID(), LOCALE_SDECIMAL)
End Function

'Purpose: Assume a date string with English separator "1/4/2006"
'Returns: Correct Date Variable
Public Function ResolveDate(ByVal sDate As String) As Date
   Dim sArray() As String
   If InStr(sDate, "/") Then 'Potentially a date string
      sArray = Split(sDate, "/")
      Debug.Print "GetUserDefaultLCID", GetUserDefaultLCID
      Debug.Print "GetSystemDefaultLCID", GetSystemDefaultLCID
      If UBound(sArray) = 2 Then 'We have 3 parts
         Select Case ShortDateOrder2
            Case doMDY '
               ResolveDate = DateSerial(sArray(2), sArray(0), sArray(1))
            Case doDMY
               ResolveDate = DateSerial(sArray(2), sArray(1), sArray(0))
            Case doYMD
               ResolveDate = DateSerial(sArray(0), sArray(1), sArray(2))
         End Select
      End If
   End If
End Function

'Purpose: Assume a number string with English separators "123,456.78"
'Returns: Correct Double Variable
Public Function ResolveNumber(ByVal sNum As String) As Double
   Dim sTS As String
   Dim sDS As String
   sTS = GetThousandsSep
   sDS = GetDecimalSep

   If (sTS = ",") And (sDS = ".") Then 'English
      'format is OK
   Else
      Dim i As Long
      Dim sMid As String
      For i = 1 To Len(sNum)
         Select Case Mid(sNum, i, 1)
            Case ","
               Mid(sNum, i, 1) = sTS
            Case "."
               Mid(sNum, i, 1) = sDS
         End Select
      Next
   End If

   ResolveNumber = CDbl(sNum)

End Function

Public Function ShortDateOrder2() As DateOrderEnum
   'Get ShortDateOrder the hard way
   Dim sShort           As String
   Dim qOn              As Boolean
   Dim i                As Integer
   Dim sChar            As String

   On Error Resume Next

   'Get the Short Date format
   sShort = pfGLI(GetUserDefaultLCID(), LOCALE_SSHORTDATE)

   For i = 1 To Len(sShort)
      sChar = Mid(sShort, i, 1)
      'Ignore items in single quotes (if any)
      If sChar = "'" Then
         qOn = Not qOn
      Else
         If Not qOn Then
            Select Case sChar
               Case "d"
                  ShortDateOrder2 = doDMY
                  Exit Function
               Case "m"
                  ShortDateOrder2 = doMDY
                  Exit Function
               Case "y"
                  ShortDateOrder2 = doYMD
                  Exit Function
            End Select
         End If
      End If
   Next
End Function

Private Function pfGLI(ByVal m_LocaleLCID As Long, ByVal reqInfo As Long) As String
   Dim Buffer As String * 255
   GetLocaleInfoA m_LocaleLCID, reqInfo, Buffer, 255
   pfGLI = StripNull(Buffer)
End Function

Public Function StripNull(ByVal StrIn As String) As String
   Dim nul              As Long
   nul = InStr(StrIn, vbNullChar)
   Select Case nul
      Case Is > 1
         StripNull = Left$(StrIn, nul - 1)
      Case 1
         StripNull = ""
      Case 0
         StripNull = Trim$(StrIn)
   End Select
End Function

From http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_21841979.html

Option Explicit

Public Enum DateOrderEnum
   doDefault 'Your locale setting
   doMDY     'Month-Day-Year (U.S.)
   doDMY     'Day-Month-Year (EU, S.A.)
   doYMD     'Year-Month-Day (Japan)
End Enum

Public Const LOCALE_SSHORTDATE As Long = &H1F
Public Const LOCALE_STHOUSAND As Long = &HF
Public Const LOCALE_SDECIMAL  As Long = &HE

Public Declare Function GetUserDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetSystemDefaultLCID Lib "kernel32" () As Long
Public Declare Function GetLocaleInfoA Lib "kernel32" (ByVal Locale As Long, ByVal LCType As Long, ByVal lpLCData As String, ByVal cchData As Long) As Long

Public Function GetThousandsSep() As String
   GetThousandsSep = pfGLI(GetUserDefaultLCID(), LOCALE_STHOUSAND)
End Function

Public Function GetDecimalSep() As String
   GetDecimalSep = pfGLI(GetUserDefaultLCID(), LOCALE_SDECIMAL)
End Function

'Purpose: Assume a date string with English separator "1/4/2006"
'Returns: Correct Date Variable
Public Function ResolveDate(ByVal sDate As String) As Date
   Dim sArray() As String
   If InStr(sDate, "/") Then 'Potentially a date string
      sArray = Split(sDate, "/")
      Debug.Print "GetUserDefaultLCID", GetUserDefaultLCID
      Debug.Print "GetSystemDefaultLCID", GetSystemDefaultLCID
      If UBound(sArray) = 2 Then 'We have 3 parts
         Select Case ShortDateOrder2
            Case doMDY '
               ResolveDate = DateSerial(sArray(2), sArray(0), sArray(1))
            Case doDMY
               ResolveDate = DateSerial(sArray(2), sArray(1), sArray(0))
            Case doYMD
               ResolveDate = DateSerial(sArray(0), sArray(1), sArray(2))
         End Select
      End If
   End If
End Function

'Purpose: Assume a number string with English separators "123,456.78"
'Returns: Correct Double Variable
Public Function ResolveNumber(ByVal sNum As String) As Double
   Dim sTS As String
   Dim sDS As String
   sTS = GetThousandsSep
   sDS = GetDecimalSep

   If (sTS = ",") And (sDS = ".") Then 'English
      'format is OK
   Else
      Dim i As Long
      Dim sMid As String
      For i = 1 To Len(sNum)
         Select Case Mid(sNum, i, 1)
            Case ","
               Mid(sNum, i, 1) = sTS
            Case "."
               Mid(sNum, i, 1) = sDS
         End Select
      Next
   End If

   ResolveNumber = CDbl(sNum)

End Function

Public Function ShortDateOrder2() As DateOrderEnum
   'Get ShortDateOrder the hard way
   Dim sShort           As String
   Dim qOn              As Boolean
   Dim i                As Integer
   Dim sChar            As String

   On Error Resume Next

   'Get the Short Date format
   sShort = pfGLI(GetUserDefaultLCID(), LOCALE_SSHORTDATE)

   For i = 1 To Len(sShort)
      sChar = Mid(sShort, i, 1)
      'Ignore items in single quotes (if any)
      If sChar = "'" Then
         qOn = Not qOn
      Else
         If Not qOn Then
            Select Case sChar
               Case "d"
                  ShortDateOrder2 = doDMY
                  Exit Function
               Case "m"
                  ShortDateOrder2 = doMDY
                  Exit Function
               Case "y"
                  ShortDateOrder2 = doYMD
                  Exit Function
            End Select
         End If
      End If
   Next
End Function

Private Function pfGLI(ByVal m_LocaleLCID As Long, ByVal reqInfo As Long) As String
   Dim Buffer As String * 255
   GetLocaleInfoA m_LocaleLCID, reqInfo, Buffer, 255
   pfGLI = StripNull(Buffer)
End Function

Public Function StripNull(ByVal StrIn As String) As String
   Dim nul              As Long
   nul = InStr(StrIn, vbNullChar)
   Select Case nul
      Case Is > 1
         StripNull = Left$(StrIn, nul - 1)
      Case 1
         StripNull = ""
      Case 0
         StripNull = Trim$(StrIn)
   End Select
End Function
苯莒 2024-09-04 13:11:21

根据您实际想要实现的目标,您可以尝试在启动过程中调用 SetThreadLocale()

Dependsing on what you're actually trying to achieve, you can try calling SetThreadLocale() in your startup procedure.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文