|
-
Jul 2nd, 2002, 08:15 AM
#1
Thread Starter
Hyperactive Member
Simple format question
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
-
Jul 2nd, 2002, 08:23 AM
#2
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, " ")
-
Jul 2nd, 2002, 08:46 AM
#3
warm smell of colitas rising up to the air
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
-
Jul 2nd, 2002, 08:53 AM
#4
Lively Member
Re: Simple format question
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.
Your attitude determines your altitude!!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|