By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,759 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,759 IT Pros & Developers. It's quick & easy.

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

P: 21
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
Jul 19 '10 #1
Share this Question
Share on Google+
4 Replies


Guido Geurs
Expert 100+
P: 767
I hope this will do the job (see attachment)

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2. Dim ARRAYTEXT() As String
  3. Dim ARRAYLINE() As String
  4. Dim i As Integer
  5.    ReDim ARRAYTEXT(0)
  6.    ReDim ARRAYLINE(0)
  7.    ARRAYTEXT = Split(Text1.Text, vbNewLine)
  8.    For i = LBound(ARRAYTEXT) To UBound(ARRAYTEXT) - 1
  9.       ARRAYLINE = Split(ARRAYTEXT(i), ",")
  10.       Text2.Text = Text2.Text & ARRAYLINE(0) & ","
  11.       Text2.Text = Text2.Text & Format(ARRAYLINE(1), "@@@@@@") & ","
  12.       Text2.Text = Text2.Text & Format(Str(ARRAYLINE(2)), "@@@@@@@@@@") & ","
  13.       Text2.Text = Text2.Text & Format(Str(ARRAYLINE(3)), "@@@@@@@") & vbNewLine
  14.    Next
  15. End Sub
Jul 19 '10 #2

P: 21
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?
Aug 9 '10 #3

Guido Geurs
Expert 100+
P: 767
Sorry for this misunderstanding 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.
Aug 10 '10 #4

P: 21
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
Aug 11 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.