我正在VB6中尝试用阿拉伯语显示日期。但它用英语显示日期。我在"区域和语言"窗口中设置了以下内容:
- 非Unicode程序的当前语言:阿拉伯语(埃及)
- 格式:阿拉伯语(埃及)
- 地点:埃及
在"地区和语言"窗口中,日期以阿拉伯语正确显示。
我使用以下代码以阿拉伯语显示日期:
MsgBox date
VB6不会开箱即用。
如果您希望将日期格式化为dd/MM/yyyy,请使用
MsgBox Format$(date, "dd/mm/yyyy")
或
MsgBox FormatDateTime(date, vbShortDate)
如本文所述,对于Arvo 所示的"短日期"
问题是MsgBox和Format不适用于非ASCII字符。简单的实验。创建带有编辑框的表单。将编辑框属性更改为
- (名称)NotMsgBox
- 多行true
-
字体Arial Unicode MS
Private Declare Function GetLocaleInfo Lib "kernel32" _ Alias "GetLocaleInfoA" ( _ ByVal locale As Long, _ ByVal lcType As Long, _ ByVal lpLCData As String, _ ByVal cchData As Long) _ As Long Const LOCALE_USER_DEFAULT = &H400 Const LOCALE_NATIVE_LANGUAGE = &H4 Const LOCALE_NATIVE_COUNTRY = &H8 Function GetInfo(ByVal info As Long) As String Dim rv As Long, data As String data = String$(256, 0) rv = GetLocaleInfo(LOCALE_USER_DEFAULT, info, data, Len(data)) If rv > 0 Then GetInfo = Left(data, rv - 1) Else GetInfo = "" End If End Function Function Whatever() As String Dim str As String str = "" str = str & "You live in " & GetInfo(LOCALE_NATIVE_COUNTRY) & vbCrLf str = str & "You speak " & GetInfo(LOCALE_NATIVE_LANGUAGE) & vbCrLf Whatever = str End Function Private Sub Form_Load() Dim str As String str = Whatever NotMsgBox.Text = str MsgBox str, vbOK, "Egyptian Arabic" End Sub
你会注意到,在Msgbox中,阿拉伯语和埃及语是一堆jibberish,但在文本框中它显示正确。如果您现在将任何内容更改为
Function Whatever() As String
Dim str As String
str = ""
str = str & "Long Date is " & Format$(Now, "Long Date") & vbCrLf
str = str & "Short Date is " & Format$(Now, "Short Date") & vbCrLf
str = str & "General Date is " & Format$(Now, "General Date") & vbCrLf
str = str & "Medium Date is " & Format$(Now, "Medium Date") & vbCrLf
str = str & "You live in " & GetInfo(LOCALE_NATIVE_COUNTRY) & vbCrLf
str = str & "You speak " & GetInfo(LOCALE_NATIVE_LANGUAGE) & vbCrLf
Whatever = str
End Function
您会注意到,在长格式和中格式中,月份显示为?????。它已经被正确地转换为阿拉伯语,但随后又被翻译回ASCII,结果加载了?。
你能做些什么?
- 编写自己的支持Unicode的消息框
- 使用FM20.dll中的ActiveX控件
- 编写自己的日期转换例程