Help with String Length Code

K

kolsby

Disclosure - never been good at VB

I want to right a funtion that will count the length of a string
(field) and put as many zeroes in front of the field until that field
is 6 characters.
example:

Field1 Desired Result
A4 0000A4
A41 000A41

I'm thinking of something like this but not sure how close i am

Function stringlen()

While Len(field1) < 6
hexno = "0" + Field1
Wend
End Function

am i close?

KO
 
D

Douglas J. Steele

It's far simpler is just to use

Right("000000" & [Field1], 6)

There were quite a few errors in your function:

Function stringlen(ValueIn As String) As String
Dim hexno As String

hexno = ValueIn
While Len(hexno) < 6
hexno = "0" + hexno
Wend

stringlen = hexno

End Function
 

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