I've got a string wich I want to right justify and the max lenght is 6 Ex: if I got 3 char in the string I would like to get 3 spaces then the 3 chars.
Ex: aaa -> ___aaa
thanks
Printable View
I've got a string wich I want to right justify and the max lenght is 6 Ex: if I got 3 char in the string I would like to get 3 spaces then the 3 chars.
Ex: aaa -> ___aaa
thanks
VB Code:
Private Function JustifyText(ByVal strText As String, ByVal intMaxLen As Integer, ByVal strFillChar As String) As String On Error Goto JustifyText_Error If intMaxLen - Len(strText) > 0 Then JustifyText = String(intMaxLen - Len(strText), strFillChar) & strText Else JustifyText = strText End If Exit Function JustifyText_Error: Err.Clear JustifyText = strText End Function
in your example:
Debug.Print JustifyText("aaa", 6, " ")
use this first param is the length of the string to return, second one your string and third the values you want to fill up
VB Code:
Public Function Numb(lengte As Integer, waarde As String, voorzetsel As String) As String Dim i As Integer Dim temp As String For i = Len(temp) + 1 To lengte temp = voorzetsel & temp Next i Numb = Right(temp, lengte) End Function
dim ln as integer
dim i, j as integer
dim str as string
ln=len(yourstring)
i = 6 - ln
if i>0 then
str=""
for j = 0 to i
str = stR & " " 'Concatenate space
next
yourstring = str & yourstring
else
yourstring=yourstring
end if
So youstring will be rightjustified. But are you sure that initially yourstring does not contain more than 6 characters.