Consulting

Results 1 to 4 of 4

Thread: Checking and correction values in userforms

  1. #1
    VBAX Regular
    Joined
    Aug 2004
    Posts
    22
    Location

    Checking and correction values in userforms

    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

  2. #2
    BoardCoder VBAX Regular
    Joined
    May 2004
    Location
    Istanbul, Turkiye
    Posts
    73
    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

  3. #3
    VBAX Regular
    Joined
    Aug 2004
    Posts
    22
    Location
    Hi Suat,

    Simple is beautiful! Always ! Thanks!

    Johannes

  4. #4
    BoardCoder VBAX Regular
    Joined
    May 2004
    Location
    Istanbul, Turkiye
    Posts
    73
    Nice to hear it helps, Johannes!

    Suat

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •