AzraSound
asked on
Someone Know about Chinese Operating System?
I need someone who can help me, preferably who runs a Chinese version of Windows, but anyone with experience with this is more than welcome to share. I have a program that uses the following function in the KeyPress event of various control's throughout the project:
Public Function ValidateNumericEntry(ctl As Control, KeyAscii As Integer) As Integer
On Error Resume Next
With ctl
If ((InStr(1, .Text, p_strDecimal) <> 0 And Chr(KeyAscii) = p_strDecimal And _
InStr(1, .SelText, p_strDecimal) = 0) Or _
(InStr(1, .Text, "-") <> 0 And Chr(KeyAscii) = "-") Or _
(Chr(KeyAscii) = "-" And .SelStart <> 0)) Then
'do not allow this key entry
ValidateNumericEntry = 0
Else
'return original value
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And _
Chr(KeyAscii) <> p_strDecimal And Chr(KeyAscii) <> "-" Then
ValidateNumericEntry = 0
Else
ValidateNumericEntry = KeyAscii
End If
End If
End With
End Function
We recently got a customer in China who says they cannot enter a decimal in the textboxes on the forms. The p_strDecimal variable in the above function corresponds to the user's regional settings and what they use as a decimal. I understand Chinese use a decimal point, same as the United States. So, any ideas? I thought it may have something to do with their double-byte character set but nothing above seems it should be an issue with regards to that, but, I could be wrong.
Public Function ValidateNumericEntry(ctl As Control, KeyAscii As Integer) As Integer
On Error Resume Next
With ctl
If ((InStr(1, .Text, p_strDecimal) <> 0 And Chr(KeyAscii) = p_strDecimal And _
InStr(1, .SelText, p_strDecimal) = 0) Or _
(InStr(1, .Text, "-") <> 0 And Chr(KeyAscii) = "-") Or _
(Chr(KeyAscii) = "-" And .SelStart <> 0)) Then
'do not allow this key entry
ValidateNumericEntry = 0
Else
'return original value
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 8 And _
Chr(KeyAscii) <> p_strDecimal And Chr(KeyAscii) <> "-" Then
ValidateNumericEntry = 0
Else
ValidateNumericEntry = KeyAscii
End If
End If
End With
End Function
We recently got a customer in China who says they cannot enter a decimal in the textboxes on the forms. The p_strDecimal variable in the above function corresponds to the user's regional settings and what they use as a decimal. I understand Chinese use a decimal point, same as the United States. So, any ideas? I thought it may have something to do with their double-byte character set but nothing above seems it should be an issue with regards to that, but, I could be wrong.
See if you can find out what is the ASCII code for the deciamal point they are using and compare it with the expected value.
ASKER
They dont have a different ASCII value for the decimal point though do they? I thought the first 255 or so characters in the ASCII chart were universal...
Maybe, and maybe they are trying to type something which just looks like a decimal point.
ASKER
I sent a debugging app to them and there decimal is the same as ours (he is pressing the right key). I tried changing the Option Compare option, but nothing seems to allow the decimal through using the validation routine above.
Ok, lets try to untangle this a bit. Lets break out this statement to see which part is failing, there may be a problem with logic of the syntax:
Change:
If ((InStr(1, .Text, p_strDecimal) <> 0 And Chr(KeyAscii) = p_strDecimal And InStr(1, .SelText, p_strDecimal) = 0) Or (InStr(1, .Text, "-") <> 0 And Chr(KeyAscii) = "-") Or (Chr(KeyAscii) = "-" And .SelStart <> 0))
To:
intPart1 = InStr(1, .Text, p_strDecimal)
intPart2 = InStr(1, .SelText, p_strDecimal)
intPart3 = InStr(1, .Text, "-")
If (intPart1 <> 0 And Chr(KeyAscii) = p_strDecimal And intPart2 = 0) Or intPart3 <> 0 And Chr(KeyAscii) = "-") Or (Chr(KeyAscii) = "-" And .SelStart <> 0)) Then
In fact for testing you may wish to get rid of the check for dash to make it less complex
intPart1 = InStr(1, .Text, p_strDecimal)
intPart2 = InStr(1, .SelText, p_strDecimal)
If (intPart1 <> 0 And Chr(KeyAscii) = p_strDecimal And intPart2 = 0)) Then
Leon
Change:
If ((InStr(1, .Text, p_strDecimal) <> 0 And Chr(KeyAscii) = p_strDecimal And InStr(1, .SelText, p_strDecimal) = 0) Or (InStr(1, .Text, "-") <> 0 And Chr(KeyAscii) = "-") Or (Chr(KeyAscii) = "-" And .SelStart <> 0))
To:
intPart1 = InStr(1, .Text, p_strDecimal)
intPart2 = InStr(1, .SelText, p_strDecimal)
intPart3 = InStr(1, .Text, "-")
If (intPart1 <> 0 And Chr(KeyAscii) = p_strDecimal And intPart2 = 0) Or intPart3 <> 0 And Chr(KeyAscii) = "-") Or (Chr(KeyAscii) = "-" And .SelStart <> 0)) Then
In fact for testing you may wish to get rid of the check for dash to make it less complex
intPart1 = InStr(1, .Text, p_strDecimal)
intPart2 = InStr(1, .SelText, p_strDecimal)
If (intPart1 <> 0 And Chr(KeyAscii) = p_strDecimal And intPart2 = 0)) Then
Leon
By the way, I know for a fact that Russian uses a comma as their decimal seperator, but I am not sure about Chinese. Just something to keep in mind.
Leon
Leon
ASKER
The logic is fine, as it has worked everywhere else (this program is used in Russia, South America, North America, China, Egypt, etc.). In fact, it works on some versions of the Chinese operating system, but apparently, not this particular one. What the difference is between this system and the other Chinese system it worked on, I will have to investigate to find out.
AzraSound,
Let me know what you find. Sorry I could not be of more help.
Leon
Let me know what you find. Sorry I could not be of more help.
Leon
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks Ark, it does simplify things, especially with regards to their regional settings and what they use as their decimal separator. With some added error handling (e.g., the text is empty, just a decimal, or just the negative sign) this could probably work as well. For now, the client was happy with us just removing the validation code altogether (if they enter text instead of a number, they understand the calculations won't work). However, thanks for that input, as it probably solves the problem since I think the issue is related to one of those internal VB functions such as Instr.
Hello again. I also think so, though it's strange because VB works with OLE strings (BSTR) which are internally unicode. I used CDbl in my programs - it correctly transfer strings irrespectivly to local decimal separator (as leonstryker mentioned above in Russia comma is using as decimal separator though I prefer point). Anyway I'm afraid you'll have to use API instead of VB Instr (BTW, have a look on SHLWAPI - there are StrStr/StrStrI and StrCSpn/StrCSpnI
'From MSDN:
Private Declare Function StrCSpn Lib "Shlwapi" _
Alias "StrCSpnW" (ByVal lpStr As Long, _
ByVal lpSet As Long) As Long
Private Declare Function StrCSpnI Lib "Shlwapi" _
Alias "StrCSpnW" (ByVal lpStr As Long, _
ByVal lpSet As Long) As Long
Public Function InstrAny(SearchString As String, _
CharList As String, _
Optional CaseSensitive As Boolean = True) As Long
' Returns the position of the first occurrence of
' a character in CharList within SearchString.
If CaseSensitive Then
nRet = StrCSpn(StrPtr(SearchStrin g), StrPtr(CharList))
Else
nRet = StrCSpnI(StrPtr(SearchStri ng), StrPtr(CharList))
End If
Select Case nRet
Case 0, Len(SearchString)
InstrAny = 0
Case Else
InstrAny = nRet + 1
End Select
End Function
Public Function ContainsAnyChar(
ByVal SearchString As String, CharList As String, _
Optional CaseSensitive As Boolean = True) As Boolean
' Returns True if SearchString contains any
' character in CharList.
ContainsAnyChar = CBool(InstrAny(SearchStrin g, _
CharList, CaseSensitive))
End Function
Regards
Ark
'From MSDN:
Private Declare Function StrCSpn Lib "Shlwapi" _
Alias "StrCSpnW" (ByVal lpStr As Long, _
ByVal lpSet As Long) As Long
Private Declare Function StrCSpnI Lib "Shlwapi" _
Alias "StrCSpnW" (ByVal lpStr As Long, _
ByVal lpSet As Long) As Long
Public Function InstrAny(SearchString As String, _
CharList As String, _
Optional CaseSensitive As Boolean = True) As Long
' Returns the position of the first occurrence of
' a character in CharList within SearchString.
If CaseSensitive Then
nRet = StrCSpn(StrPtr(SearchStrin
Else
nRet = StrCSpnI(StrPtr(SearchStri
End If
Select Case nRet
Case 0, Len(SearchString)
InstrAny = 0
Case Else
InstrAny = nRet + 1
End Select
End Function
Public Function ContainsAnyChar(
ByVal SearchString As String, CharList As String, _
Optional CaseSensitive As Boolean = True) As Boolean
' Returns True if SearchString contains any
' character in CharList.
ContainsAnyChar = CBool(InstrAny(SearchStrin
CharList, CaseSensitive))
End Function
Regards
Ark