Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Formating strings in VB6

Formating strings in VB6

Scheduled Pinned Locked Moved Visual Basic
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    No e
    wrote on last edited by
    #1

    I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator

    S G 2 Replies Last reply
    0
    • N No e

      I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator

      S Offline
      S Offline
      SNathani
      wrote on last edited by
      #2

      Hello No-e, You have to write the data as fixed length column files. Determine your output fields and find out the best fit MAX length of the data for each column. Then use VB/VB.net LSet(), RSet() functions are Trim() functions to write your columns in fixed length. Hope this will help you solve your problem. Nathhani

      1 Reply Last reply
      0
      • N No e

        I am saving results to a text file and want my information to line up in nice little columns Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 But what I get using VBTAB is inconsistent: Name Status Extra Info Test A Pass 10.0 Test B with longer name Fail 7.5 Test C, short Name Pass 17.5 Not sure if I can use a format function of not, documentation does not supply much info on format for text strings, just dates and numbers I understand the fonnts can not be a serif font, this is just for display to an operator

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        A text file has no formatting capabilities, so you have to use spaces to line them up, and specify for anyone who will be using it to use a non-proporional font when displaying it. You can use alignment in composite formatting to line up the columns. Example from MSDN:

        string myFName = "Fred";
        string myLName = "Opals";
        int myInt = 100;
        string FormatFName = String.Format("First Name = |{0,10}|", myFName);
        string FormatLName = String.Format("Last Name = |{0,10}|", myLName);
        string FormatPrice = String.Format("Price = |{0,10:C}|", myInt);
        Console.WriteLine(FormatFName);
        Console.WriteLine(FormatLName);
        Console.WriteLine(FormatPrice);

        FormatFName = String.Format("First Name = |{0,-10}|", myFName);
        FormatLName = String.Format("Last Name = |{0,-10}|", myLName);
        FormatPrice = String.Format("Price = |{0,-10:C}|", myInt);
        Console.WriteLine(FormatFName);
        Console.WriteLine(FormatLName);
        Console.WriteLine(FormatPrice);

        Example output:

        First Name = | Fred|
        Last Name = | Opals|
        Price = | $100.00|
        First Name = |Fred |
        Last Name = |Opals |
        Price = |$100.00 |

        --- b { font-weight: normal; }

        C 1 Reply Last reply
        0
        • G Guffa

          A text file has no formatting capabilities, so you have to use spaces to line them up, and specify for anyone who will be using it to use a non-proporional font when displaying it. You can use alignment in composite formatting to line up the columns. Example from MSDN:

          string myFName = "Fred";
          string myLName = "Opals";
          int myInt = 100;
          string FormatFName = String.Format("First Name = |{0,10}|", myFName);
          string FormatLName = String.Format("Last Name = |{0,10}|", myLName);
          string FormatPrice = String.Format("Price = |{0,10:C}|", myInt);
          Console.WriteLine(FormatFName);
          Console.WriteLine(FormatLName);
          Console.WriteLine(FormatPrice);

          FormatFName = String.Format("First Name = |{0,-10}|", myFName);
          FormatLName = String.Format("Last Name = |{0,-10}|", myLName);
          FormatPrice = String.Format("Price = |{0,-10:C}|", myInt);
          Console.WriteLine(FormatFName);
          Console.WriteLine(FormatLName);
          Console.WriteLine(FormatPrice);

          Example output:

          First Name = | Fred|
          Last Name = | Opals|
          Price = | $100.00|
          First Name = |Fred |
          Last Name = |Opals |
          Price = |$100.00 |

          --- b { font-weight: normal; }

          C Offline
          C Offline
          ChandraRam
          wrote on last edited by
          #4

          The example is for VB.NET though... will need to pad with spaces in VB6. Chandra

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups