Remove Leading Zeros

J

Jim

I have this that I kludge together using other code I found: (I am a
newbie)

Sub EnterField()
Dim dlg As frmPIDEntry
Set dlg = New frmPIDEntry
With dlg
.bCancel = False
.Show
If Not .bCancel Then
ActiveDocument.FormFields( _
Selection.Bookmarks(1).Name).Result = _
.tbxDrug.Value & "-" & .tbxProtocol.Value & "-" &
..tbxDrug.Value & "-" & .tbxPID.Value

End If
End With
Set dlg = Nothing
End Sub

I use a Userform to drive this as data entry on a Word from. What I
want is to be able to remove leading zeros from values prior to the
Word field being filled. So for example if in the textbox .tbxProtocol
someone enters 007 or 017 it is converted to 7 (or 17). I thought I
could use CLng but I can't get it to work.
 
K

karitaat

Jim,

use the Val function
Val("017") returns the value 17
You might want to combine it with the Str function:
Str(Val("007")) retuns the string "7"

Also: have a look at Trim: this removes leading and trailing spaces.

Regards,
peter


Jim schreef:
 
J

Jim

Peter,

thanks, I did get CLng to work as I noticed in the tbxDrug listed
twice but Val also works.

Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top