Results 1 to 6 of 6

Thread: how to create fixed length string??

  1. #1

    Thread Starter
    Lively Member Cerebrate's Avatar
    Join Date
    May 2000
    Posts
    82

    Question

    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

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    Hasn't this already been anwered in the VB-General forum?

    you could do somthing like this to pad out teh sring with spaces:
    Code:
    strTemp = left(strTemp & space(10),10))
    Mark
    -------------------

  3. #3
    Junior Member
    Join Date
    Jan 1999
    Posts
    30
    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

  4. #4

    Thread Starter
    Lively Member Cerebrate's Avatar
    Join Date
    May 2000
    Posts
    82

    Cool I know..

    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

  5. #5
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845

    The plot thickens....

    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!
    Mark
    -------------------

  6. #6

    Thread Starter
    Lively Member Cerebrate's Avatar
    Join Date
    May 2000
    Posts
    82

    Cool

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width