right justify a string

right justify a string

Anonymous
Not applicable
691 Views
6 Replies
Message 1 of 7

right justify a string

Anonymous
Not applicable
Hopefully there is an easy answer to this question but I'm at a lose for the
moment.

Dim X As String * 10

X = "1.000"

I want X to equal " 1.000"

Thanks!

Joe ...
0 Likes
692 Views
6 Replies
Replies (6)
Message 2 of 7

mdhutchinson
Advisor
Advisor
... doesn't work to simply embed a space?
X = " 1.0000"
0 Likes
Message 3 of 7

Anonymous
Not applicable
Nope, but I came up with this solution. Watch out for word-wrapping!

Joe ...


Public Function RightJustifyFixedLengthString(FixedLengthString As String)
As String
FixedLengthString = Right(FixedLengthString, Len(FixedLengthString) -
Len(RTrim(FixedLengthString))) & RTrim(FixedLengthString)
End Function

Public Sub Test()
Dim FixedLengthString As String * 10
FixedLengthString = "1.000"
RightJustifyFixedLengthString FixedLengthString
Debug.Print FixedLengthString
End Sub


wrote in message news:5540385@discussion.autodesk.com...
... doesn't work to simply embed a space?
X = " 1.0000"
0 Likes
Message 4 of 7

Ed__Jobe
Mentor
Mentor
Hi Joe. Should the function return the value, like this:
[code]
Public Function RightJustifyFixedLengthString(FixedLengthString As String) As String
RightJustifyFixedLengthString = Right(FixedLengthString, Len(FixedLengthString) - _
Len(RTrim(FixedLengthString))) & RTrim(FixedLengthString)
End Function[/code]

Also, this worked for me. It padded two spaces in front.
[code]
FixedLengthString = "1.000"
FixedLengthString = " " & FixedLengthString[/code]
You would just have to calculate how many spaces to use. Granted, that might take more code than what you came up with, but it just seemed like you were saying that adding spaces didn't work.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 5 of 7

Anonymous
Not applicable
Ed,

That's what my code does. It takes the len of the whole string - the length
of the actual string = the amount of space needed. Then concate the actual
string to the pad and that's it.

Joe ...


wrote in message news:5540481@discussion.autodesk.com...
Hi Joe. Should the function return the value, like this:
[code]
Public Function RightJustifyFixedLengthString(FixedLengthString As String)
As String
RightJustifyFixedLengthString = Right(FixedLengthString,
Len(FixedLengthString) - _
Len(RTrim(FixedLengthString))) & RTrim(FixedLengthString)
End Function[/code]

Also, this worked for me. It padded two spaces in front.
[code]
FixedLengthString = "1.000"
FixedLengthString = " " & FixedLengthString[/code]
You would just have to calculate how many spaces to use. Granted, that might
take more code than what you came up with, but it just seemed like you were
saying that adding spaces didn't work.
0 Likes
Message 6 of 7

Ed__Jobe
Mentor
Mentor
Yes, I knew that, but I think I misread Hutch's response and therefore what you were saying "Nope" to. Sorry.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

0 Likes
Message 7 of 7

Anonymous
Not applicable
Not a problem, I appreciate the feedback.

Joe ...


wrote in message news:5541209@discussion.autodesk.com...
Yes, I knew that, but I think I misread Hutch's response and therefore what
you were saying "Nope" to. Sorry.
0 Likes