PDA

View Full Version : Solved: Checking and correction values in userforms



Johannes
09-09-2004, 11:20 AM
While on the subject of userforms; I have a problem with a userform where the user is asked to enter a decimal value in one of the fields. The problem is that this 'application' is to be used by different users who have their default decimal settings on their PC both as , (comma) and . (stop). Somehow this messes up as VBA in some situations will not understand the decimal point that is entered as exactly that.

How can I easily check the value for which type of decimal point that is entered and change that to . ?

I have for the moment solved it like this when the user clicks the OK button to close the userform:



Private Sub OKButton_Click()
Interval= Userform.Interval.Value
If Not IsNumeric(Interval) Then
MsgBox ("Interval does not contain numeric value")
Else
Userform.Hide
End If
End Sub



What I think I need to do is to use Search..Replace to search the variable Interval for the , and replace it with a .

I know it must be easy but after a long day at work my head just doesn't seem to work..

Johannes

smozgur
09-09-2004, 12:45 PM
Hi Johannes,

Application.International(xlDecimalSeparator) returns the local PC decimal seperator according to that PC's settings.

Private Sub Interval_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Application.International(xlDecimalSeparator) = "," Then
UserForm.Interval.Value = Replace(UserForm.Interval.Value, ",", ".")
End If
End Sub

Actually I am probably missing something in your question because we can just use


UserForm.Interval.Value = Replace(UserForm.Interval.Value, ",", ".")


to replace all commas to "." without checking the user settings. However if you need to know user settings and decimal seperator then you can use the International property of Application object as I mentioned above.

Suat

Johannes
09-09-2004, 02:12 PM
Hi Suat,

Simple is beautiful! Always ! Thanks!

Johannes

smozgur
09-09-2004, 02:24 PM
Nice to hear it helps, Johannes!

Suat