function needed

G

Guest

Hi,
is there a function in VBA that can do following:
I want to specify string X, char A , and length N of resultant string.
Function should fill string X from left with char A so resultant string would
be N long.
eg. F('abc','x', 6) = 'xxxabc'
Thanx
alekmil
 
A

Arvin Meyer

This is similar to the older LPad function which was part of the
NeatCode.mdb distributed years ago for Access 2.0:

Function LeftFill(strIn As String, ByVal strChr As String, intCount As
Integer) As String

' Adds a character (strChr) to the left of strIn to make it right justified
' by intCount characters
On Error Resume Next

If Len(strChr) = 0 Then strChr = " "
If intCount < 1 Then
LeftFill = ""
Else
LeftFill = Right(String(intCount, Left(strChr, 1)) & strIn, intCount)
End If

End Function
--
Arvin Meyer, MCP, MVP
Microsoft Access
Free Access downloads:
http://www.datastrat.com
http://www.mvps.org/access
 

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