|
-
April 4th, 2001, 06:24 AM
#1
String Manupilation
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
-
April 4th, 2001, 06:55 AM
#2
Re: String Manupilation
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.
...at present time, using mainly Net 4.0, Vs 2010
Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
all the other wonderful people who made and make Codeguru a great place.
Come back soon, you Gurus.
-
April 4th, 2001, 07:02 AM
#3
Re: String Manupilation
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
-
April 4th, 2001, 09:46 AM
#4
Re: String Manupilation
Thanks Mr. Duffy and Cimperali - Lset/Rset - did the job 100%.
Much Appreciated
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
|