CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2000
    Location
    SA
    Posts
    11

    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


  2. #2
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    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.

  3. #3
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    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

  4. #4
    Join Date
    Aug 2000
    Location
    SA
    Posts
    11

    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
  •  





Click Here to Expand Forum to Full Width

Featured