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. C#
  4. Writing To A Text File

Writing To A Text File

Scheduled Pinned Locked Moved C#
helpquestion
12 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.
  • C Colin Angus Mackay

    rowdykuttan wrote:

    when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1

    Then check the lenth first, and if it is too large then truncate it. Or increase the space in the format.


    Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

    R Offline
    R Offline
    rowdykuttan
    wrote on last edited by
    #3

    am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY, is there any way i can specify X & Y positions in text file or printer

    C 1 Reply Last reply
    0
    • R rowdykuttan

      Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance

      M Offline
      M Offline
      Matthew Cuba
      wrote on last edited by
      #4

      If PITEMNAME's length is > 45, it is going to push everything over. You could truncate at 45 or you look at all the PITEMNAME values (assuming you are looping and trying to dump out data in columns) and set the pad accordingly rather than specifying 45. If you are limited to your width and 45 is max, truncating is what I'd do, probably. Good Luck!

      It isn't enough to do well in life. One must do good when and where one can. Otherwise, what's the point?

      1 Reply Last reply
      0
      • R rowdykuttan

        am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY, is there any way i can specify X & Y positions in text file or printer

        C Offline
        C Offline
        Colin Angus Mackay
        wrote on last edited by
        #5

        rowdykuttan wrote:

        am sending this text file to a DOT MATRIX printer, that too to a PREPRINTED STATIONARY

        You might like to specify that next time. It helps people understand your problem. If you have a fixed external constraint like the size of preprinted paper then you have to truncate the information printed. Lop off a few characters. You'll find an appropriate method on the string class. Subseq, Substring or some such thing.

        rowdykuttan wrote:

        is there any way i can specify X & Y positions in text file

        If the file is formated as fixed length lines then you can calculate any XY position in the file and Seek to it. (Y*LineLength) + X LineLength includes the two character line feed and carriage return characters. It also assumes a fixed 8-bit character encoding.


        Upcoming FREE developer events: * Glasgow: db4o: An Embeddable Database Engine for Object-Oriented Environments, Mock Objects, SQL Server CLR Integration, Reporting Services ... My website

        1 Reply Last reply
        0
        • R rowdykuttan

          Hi all while am writing to a text file using the way PrintTextWrite.WriteLine(PSLNO.PadRight(3) + " " + PKCODE.PadRight(14) + " " + PITEMNAME.PadRight(45) + " " + PQTY.PadLeft(40) + " " + PRT.PadRight(11) + " " + PTOT1.PadLeft(20)); when PITEMNAME length increases there is alignment problem for PQTY & PRT & PTOT1 am i doing it proper way or is there any other way to set format for text file ??? thanks in advance

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #6

          Are you looking to do something like this?

          1 George Washington April 30, 1789
          2 John Adams March 4, 1797
          3 Thomas Jefferson March 4, 1801
          4 James Madison March 4, 1809
          5 James Monroe March 4, 1817
          6 John Quincy Adams March 4, 1825
          7 Andrew Jackson March 4, 1829
          8 Martin Van Buren March 4, 1837
          9 William H. Harrison
          March 4, 1841
          10 John Tyler April 4, 1841

          R 1 Reply Last reply
          0
          • P PIEBALDconsult

            Are you looking to do something like this?

            1 George Washington April 30, 1789
            2 John Adams March 4, 1797
            3 Thomas Jefferson March 4, 1801
            4 James Madison March 4, 1809
            5 James Monroe March 4, 1817
            6 John Quincy Adams March 4, 1825
            7 Andrew Jackson March 4, 1829
            8 Martin Van Buren March 4, 1837
            9 William H. Harrison
            March 4, 1841
            10 John Tyler April 4, 1841

            R Offline
            R Offline
            rowdykuttan
            wrote on last edited by
            #7

            yes exactly but for William H. Harrison its comming in next line, i have left space for it like 1 George Washington April 30, 1789 2 John Adams March 4, 1797 3 Thomas Jefferson March 4, 1801 4 James Madison March 4, 1809 5 James Monroe March 4, 1817 6 John Quincy Adams March 4, 1825 7 Andrew Jackson March 4, 1829 8 Martin Van Buren March 4, 1837 9 William H. Harrison March 4, 1841 10 John Tyler April 4, 1841 i have enough space like this after name, plz tell me how to do it

            P 1 Reply Last reply
            0
            • R rowdykuttan

              yes exactly but for William H. Harrison its comming in next line, i have left space for it like 1 George Washington April 30, 1789 2 John Adams March 4, 1797 3 Thomas Jefferson March 4, 1801 4 James Madison March 4, 1809 5 James Monroe March 4, 1817 6 John Quincy Adams March 4, 1825 7 Andrew Jackson March 4, 1829 8 Martin Van Buren March 4, 1837 9 William H. Harrison March 4, 1841 10 John Tyler April 4, 1841 i have enough space like this after name, plz tell me how to do it

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #8

              You'll have to use <pre> tags in your response so I can see your formatting. Just modify your response, then I'll have another look.

              R 1 Reply Last reply
              0
              • P PIEBALDconsult

                You'll have to use <pre> tags in your response so I can see your formatting. Just modify your response, then I'll have another look.

                R Offline
                R Offline
                rowdykuttan
                wrote on last edited by
                #9

                1 George Washington April 30, 1789
                2 John Adams March 4, 1797
                3 Thomas Jefferson March 4, 1801
                4 James Madison March 4, 1809
                5 James Monroe March 4, 1817
                6 John Quincy Adams March 4, 1825
                7 Andrew Jackson March 4, 1829
                8 Martin Van Buren March 4, 1837
                9 William H. Harrison March 4, 1841
                10 John Tyler April 4, 1841

                P 1 Reply Last reply
                0
                • R rowdykuttan

                  1 George Washington April 30, 1789
                  2 John Adams March 4, 1797
                  3 Thomas Jefferson March 4, 1801
                  4 James Madison March 4, 1809
                  5 James Monroe March 4, 1817
                  6 John Quincy Adams March 4, 1825
                  7 Andrew Jackson March 4, 1829
                  8 Martin Van Buren March 4, 1837
                  9 William H. Harrison March 4, 1841
                  10 John Tyler April 4, 1841

                  P Offline
                  P Offline
                  PIEBALDconsult
                  wrote on last edited by
                  #10

                  Are you saying you want to adjust all the lines to account for the longest?

                  R 1 Reply Last reply
                  0
                  • P PIEBALDconsult

                    Are you saying you want to adjust all the lines to account for the longest?

                    R Offline
                    R Offline
                    rowdykuttan
                    wrote on last edited by
                    #11

                    yes exactly

                    P 1 Reply Last reply
                    0
                    • R rowdykuttan

                      yes exactly

                      P Offline
                      P Offline
                      PIEBALDconsult
                      wrote on last edited by
                      #12

                      Ah, then scan through the data keeping track of the longest value length, then go through printing using those values.

                      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