Results 1 to 5 of 5

Thread: how to fix string length ?

  1. #1

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

    Red face

    I have couple data 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
    Addicted Member
    Join Date
    Jan 1999
    Posts
    239

    Talking

    Look up the Trim property in VB Help

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946
    not trim...
    it's fixed length strings.

    Type Record
    strName as string * 10
    End Type

    'all records in strname will take 10 spaces
    'all records saved will occupy 10 spaces

    I haven't realy played with this..just once in
    school...for fixed lenght I use an Access Data Base

    hope it helps you in some way.

    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    Fixed-lengths strings are a good choice. Alternatively, you could use the Format$ function, like this:

    strField = Format$("whatever", "!@@@@@@@@@@")

    In the Format$ function, "at" signs (@) will normally right-justify an item in a field of that many positions (i.e., 10 @ signs = 10-position output area). By placing an exclamation point (!) in front of the @ signs, you force the data to be left-justified.
    "It's cold gin time again ..."

    Check out my website here.

  5. #5
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    use the str$(length, character) function.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

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