Click to See Complete Forum and Search --> : String Manupilation
Jaleo
April 4th, 2001, 06:24 AM
How do I go about to right justify the contents of a string type variable? Alternatively - how can I write numeric data to a fixed length field if I can only specify the length with a string type eg.
Private Type Outputrec
Invoice As String * 8
End Type
My data is variable in length and I need to left justify string data and right justify numeric data in fields forming part of a fixed length record in a fixed length file.
Thanks
Cimperiali
April 4th, 2001, 06:55 AM
You can declare a fixed len string
dim myfixstring as string * 8
then you can fill a string with your numbers
dim mytempstring as string
mytempstring= "1234"
then you can look for length of tempstring
dim lenofstring as integer
lenofstring=len(mytempstring)
now you can build in your fixed string nonsignificant zeros or spaces to the left and number you have to the right:
myfixstring= spaces(lenofstring) & mytempstring
or
for i = 1 to lenofstring
myfixstring= myfixstring & mid(myfixstring, "0", i)
next i
myfixstring= left(myfixstring,lenofstring)& mytempstring
I have write this on memory...you may have to adjust it
Special thanks to Lothar "the Great" Haensler. Come back soon, you Guru.
John G Duffy
April 4th, 2001, 07:02 AM
Look at the Lset and Rset functions. They will allow left or tight justification of data i fixed length strings.
Quick example
private Sub Form_Load()
Dim strString as string * 20
me.Show
strString = Space(20)
LSet strString = "Left Justify"
print strString
RSet strString = "Right Justify"
print strString
End Sub
John G
Jaleo
April 4th, 2001, 09:46 AM
Thanks Mr. Duffy and Cimperali - Lset/Rset - did the job 100%.
Much Appreciated
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.