2
votes

I have a field on a form called "fin_Paiement". What I want to do is: the field value to accept only numbers and points and to replace any other character by a point. I did it for alphabetic values with replace funciton but it doesn't work. I tried this :

Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim db As NotesDatabase
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document
doc.fin_Paiement = Replace(doc.fin_Paiement_Montant(0), "*[a-z,A-Z]*", ".")

I will appreciate your help! Thanks

3

3 Answers

5
votes

Create a function which changes all non-digits to dots

Function ToDigitsAndDots(orig As String) As String
    Dim i As Integer
    Dim char As String
    For i=1 To Len(orig)
        char = Mid(orig, i, 1)
        If Not char Like "#" Then char = "."
        JustDigitsAndDots = JustDigitsAndDots & char
    Next
End Function

and change your code line to

doc.fin_Paiement = ToDigitsAndDots(doc.fin_Paiement_Montant(0))
0
votes

LotusScript's Replace method doesn't support regular expressions. You would have to make the second parameter an array of all letters, for example:

doc.fin_Paiement = Replace(
 Cstr(doc.fin_Paiement_Montant(0)),
 Split("a, b, c, d, e, f, g, h, i, j, you get the idea...", ", "),
 "."
)

Note, I haven't tested this but in theory it should do the trick.

0
votes

Please relieve me of an awful doubt : your field is of type "Number", isn't it ? In which case, no code is needed, it accepts only numbers, and the decimal separator is specified in its properties. By default, the locale settings for a field are those of the Notes client, which, by default, are those of the operating system, so normally not something you should worry about.

Anyway, this is the kind of thing you typically don't do in LotusScript ! Most straightforward is to use @functions in one of the field's events.

Check your Designer Help, here is some hint , and you may want to review this.