PDA

Click to See Complete Forum and Search --> : how to create fixed length string??


Cerebrate
Jun 26th, 2000, 02:06 AM
I have couple data I want to save it into a txt file, but it's very hard to aligh it, because the length of data are different, so I am thinking if I can fix the length of them, it will be much easier to format my txt file.

like fix length to 10:

"John" will become "John "
add space to it.

is there any function can do this?
or do you have better sugestions?


Thanks

Cerebrate

Mark Sreeves
Jun 26th, 2000, 02:13 AM
Hasn't this already been anwered in the VB-General forum?

you could do somthing like this to pad out teh sring with spaces:


strTemp = left(strTemp & space(10),10))

DrBrain
Jun 26th, 2000, 02:35 AM
Use "* 10" to fix the len of a string to 10 chr. Then when you use Put and Get to read and write.



'Save Info
Dim sOutput as String * 10
Open aFile for Output as #1
Put #1 ,sOutput
Close #1


'Read Info
Dim sInput as String * 10
Open aFile for Input as #1
Get #1,, sInput
Close #1

Cerebrate
Jun 26th, 2000, 04:10 AM
sorry about double posting..
the reason I post this Q here again is because this is for my web page, not VB application, so some function cannot be used in VBScript, such as Format$,
and....... I believe I cannot Dim some variable as String in VBScript. right? all variables are declared as variant.

can I do this "Dim str as String" in VBScript?

thanks for all help.
actually, I write a function myself for this Q.
-----------------------------------------------------
fixStrLen = dataStr & string(size - len(dataStr)," ")
-----------------------------------------------------
"size" is the size of string you want to be fixed
"dataStr" is the origional string.

Cerebrate

Mark Sreeves
Jun 26th, 2000, 03:10 PM
But why do you want to pad strings with spaces on a html page?

unless used within <pre> tags, the browsers reduce all spaces to one space.




Just tell me to mind my own business if you like! ;)

Cerebrate
Jun 26th, 2000, 11:12 PM
I want to store couple data to a txt file and then email it to someone, so with fixed string, it will be nice and neat to read.