I have a program that prints a text file from notepad at the press of a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • miroku800
    New Member
    • Mar 2007
    • 21

    I have a program that prints a text file from notepad at the press of a button

    the resulting printout looks like this
    1,blue,12345678 ,54
    2,red,00001234, 6
    3,blue,12345678 ,63
    4,blue,12345678 ,65
    5,red,00001234, 17

    Is there any way to format it into columns and then print it so it looks like this
    1,-----blue,-----12345678,-----54
    2,-----red, -----00001234,-----6
    3,-----blue,-----12345678,-----63
    4,-----blue,-----12345678,-----65
    5,-----red, -----00001234,-----17

    (ignore the hyphens as they are only there to provide a layout as the page here removes extra spaces)

    the text file is generated by an old dos based program run from an exe file called from within VB and as such would be difficult to modify I fear

    Many thanks for any suggestions

    regards Rob
  • Guido Geurs
    Recognized Expert Contributor
    • Oct 2009
    • 767

    #2
    I hope this will do the job (see attachment)

    Code:
    Private Sub Command1_Click()
    Dim ARRAYTEXT() As String
    Dim ARRAYLINE() As String
    Dim i As Integer
       ReDim ARRAYTEXT(0)
       ReDim ARRAYLINE(0)
       ARRAYTEXT = Split(Text1.Text, vbNewLine)
       For i = LBound(ARRAYTEXT) To UBound(ARRAYTEXT) - 1
          ARRAYLINE = Split(ARRAYTEXT(i), ",")
          Text2.Text = Text2.Text & ARRAYLINE(0) & ","
          Text2.Text = Text2.Text & Format(ARRAYLINE(1), "@@@@@@") & ","
          Text2.Text = Text2.Text & Format(Str(ARRAYLINE(2)), "@@@@@@@@@@") & ","
          Text2.Text = Text2.Text & Format(Str(ARRAYLINE(3)), "@@@@@@@") & vbNewLine
       Next
    End Sub
    Attached Files

    Comment

    • miroku800
      New Member
      • Mar 2007
      • 21

      #3
      My apologies for not replying sooner but I hadn't realised there was a reply to my query before the project was pushed 'to the back burner' by other works
      I have had a look at the little program you did but am puzzled as to where the original text comes from, can I insert it from a file?

      Comment

      • Guido Geurs
        Recognized Expert Contributor
        • Oct 2009
        • 767

        #4
        Sorry for this misunderstandin g but in my first answer I had only attached an example with the code how to format the data.
        The data was fix in the Textbox1.

        Now that I know that Your data is in a file, I have modified the code so You can read the data from a file and write it back to the disk.
        Attached Files

        Comment

        • miroku800
          New Member
          • Mar 2007
          • 21

          #5
          Thats absolutely brilliant, I will be able to add that to the bit I have already got and with a little bit of 'tweaking' almost make it 'idiot proof'
          You have certainly used some 'hi-tech' expressions that I have never come across before, so I can't thank you enough

          Comment

          Working...