Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a tricky one...

Status
Not open for further replies.

Eek

Technical User
Feb 4, 2001
34
CA
my program is to be use on English and french version of Windows...the problem is that in english 10.00 is OK but in french they use a "," for decimals as in 10,00 ...entering 10.00 will give an error....I tried the formatnumber and formatcurrency but still get an error.

The only solution I found is to check every text field using the Isnumeric and if it's = false then I use the Left and Right statement to check every digit in each text field and if it sees a "." for a decimal it changes it to a "," to make if french compatible.

Since the data in the text fields may have between 1-10 decimals it's hard to know where the decimal dot will be, therefore I need to check everything...

Is there anything that will convert the data depending on Windows regional settings ? I thought text1.text=formatnumber(text1.text,2) would work but it doesn't...


If you answer this one I'll owe you a beer !


Cheers !
 
You should be able to write this so you don't have to mess around with changing periods to commas, as long as the user has the appropriate International settings in the Control Panel. But I don't quite know what to tell you, because I don't know where your data is coming from, nor what kind of error you're getting if you don't fix it.

A few guidelines: Keep your numeric values in numeric variables as much as possible. You shouldn't have to worry about text boxes on forms and reports; if the International settings are set appropriately, Access should take care of the comma/period problem.

If you have to convert a numeric variable to a string, use the Format function, and use only named formats if possible. If you can't use a named format, you'll have to detect the language setting and supply an appropriate format string.

Avoid using the Val function, which isn't internationally aware. Use CSng or CDbl or CCurr instead.

Ok, now where do these numbers come from, and what kind of problem do you have if you don't convert "." to ","? Rick Sprague
 
Oops! I forgot I was in the VB forum, not Access. Still, don't bound controls on a form convert numbers using the Control Panel language settings? If you've got an unbound control, use CSng or CDbl to convert it. Rick Sprague
 
my program does financial calculations, the user fills in a few text boxes on my form and my program processes the data.

I get a runtime error each time I enter a "." for decimal on a french windows
 
"further info...", are you the same person as Eek?

If so, are you saying you want the French speaking users to use English number conventions? Why? Because they're entering dollars? Ok, that's a problem. Currency conversion is one of the few places that VB's internationalization isn't very convenient.

If that's what you really want, then the preferred solution would be to have them change their Control Panel International settings while they're using your database. Unfortunately, that could mean any other windows they're using at the same time might malfunction. The only alternative, though, is for you to write all this code to change "," to "." or vice versa.

At least I can help a little. Instead of looking through your string a character at a time, use the Replace() function. It does all the searching for you, which will save you writing so much repetitive code. Rick Sprague
 
try this Function :

Function checknum(Source As TextBox, min As Currency, max As Currency, dec As Integer, KeyAscii As Integer)

Dim key As String
Dim newvalue As Variant
Dim p As Integer

key = Chr$(KeyAscii)

Select Case key

Case "-"

If min >= 0 Then
Beep
KeyAscii = 0
Exit Function
End If

Case "0" To "9", "-"

newvalue = Val(Left$(Source, Source.SelStart) + key + Mid$(Source, Source.SelStart + Source.SelLength + 1))
If newvalue > max Or newvalue < min Then
Beep
KeyAscii = 0
End If

Case &quot;,&quot;, &quot;.&quot;

If Chr$(KeyAscii) = &quot;.&quot; Then
KeyAscii = Asc(&quot;,&quot;)
End If
If dec = 0 Or InStr(Source, &quot;,&quot;) Then
Beep
KeyAscii = 0
ElseIf Source.SelStart = 0 Then
SendKeys &quot;0,&quot;
KeyAscii = 0
End If

Case Chr$(8)

Case Else

Beep
KeyAscii = 0

End Select

If key = &quot;-&quot; And (InStr(Source, &quot;-&quot;) Or Source.SelStart <> 0) Then
Beep
KeyAscii = 0
End If

If dec >= 0 Then
If Source.SelStart > InStr(Source, &quot;,&quot;) Then
If InStr(Source, &quot;,&quot;) Then
If KeyAscii = 8 Then
p = Len(Source) - InStr(Source, &quot;,&quot;) - 1
Else
p = Len(Source) - InStr(Source, &quot;,&quot;) + 1
End If
If p > dec Then
Beep
KeyAscii = 0
End If
End If
End If
End If

checknum = KeyAscii

End Function

Example (convert to Euro,5 digits )

Private Sub txtEuro_KeyPress(KeyAscii As Integer)
KeyAscii = checknum(txtEuro, -9999999, 999999999, 5, KeyAscii)

End Sub



Eric De Decker
vbg.be@vbgroup.nl

License And Copy Protection AxtiveX.

Download Demo version on my Site:
 
In principle, the Replace can do the job. However it's not obvious to use it, when the number contains Thousands separator marks, besides the Decimal separator e.g. 1,000.25 (US notation).

The function ConvertNumberFormat converts numbers from one standard into another and may be used on systems where the user does enter numbers in another format than the Locale specifies. The converted number can then be used in the appropriate routines for further manipulation. Suggested use is in the LostFocus event of a textBox.

Private Enum rvbNumberFormat
rvbContinental
rvbNewWorld
End Enum

Const c_rvDot As String = &quot;.&quot;
Const c_rvComma As String = &quot;,&quot;

Public Sub Main()

Dim strSomeNumber As String
strSomeNumber = InputBox(&quot;Enter a Number in NewWorld Notation&quot;)


'The format of the number you enter MUST be in the NewWorld notation.

strSomeNumber = ConvertNumberFormat(strSomeNumber, rvbNewWorld, rvbContinental)

MsgBox strSomeNumber

End Sub

Private Function ConvertNumberFormat(ByVal strOldFormatNumber As String, _
rvbOldFormat As rvbNumberFormat, rvbNewFormat As rvbNumberFormat) _
As String


'WARNING: This function DOES NOT CHECK if the Format of the number you
' enter (strOldFormatNumber) is already the target (rvbNewFormat) Format.
' If this is the case, the results are unpredictable: they may or may not be
' correct, depending on the presence of ThousandsMarkers


Dim strOldDecimalMark As String, strNewDecimalMark As String
Dim strOldThousandsMark As String, strNewThousandsMark As String

If rvbOldFormat = rvbNewFormat Then GoTo PROC_EXIT

Select Case rvbOldFormat
Case rvbContinental
strOldDecimalMark = c_rvComma
strOldThousandsMark = c_rvDot
Case rvbNewWorld
strOldDecimalMark = c_rvDot
strOldThousandsMark = c_rvComma
Case Else
GoTo PROC_EXIT
End Select

Select Case rvbNewFormat
Case rvbContinental
strNewDecimalMark = c_rvComma
strNewThousandsMark = c_rvDot
Case rvbNewWorld
strNewDecimalMark = c_rvDot
strNewThousandsMark = c_rvComma
Case Else
GoTo PROC_EXIT
End Select


'Split number into integer and fraction

Dim astrOldFormatNumber() As String
astrOldFormatNumber = Split(strOldFormatNumber, strOldDecimalMark)


'Split integer part into thousands

Dim astrIntegerPart() As String
astrIntegerPart = Split(astrOldFormatNumber(0), strOldThousandsMark)


'Reconstruct integer part with new thousand mark

Dim strNewIntegerPart As String
strNewIntegerPart = Join(astrIntegerPart, strNewThousandsMark)
astrOldFormatNumber(0) = strNewIntegerPart


'Reconstruct number in new format

ConvertNumberFormat = Join(astrOldFormatNumber, strNewDecimalMark)

PROC_EXIT:
Exit Function

End Function
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top