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

How do I print MSFlexGrid data?

P: n/a
I've written a simple program in VB 6.0 to list all my MP3 files. To show
them on the screen I used an MSFlexGrid named TextGrid (which is not
associated with any table or text file) in the following code run by a
button (the files are all in the format "Artist - Name Of Song" in their
directories, which is why the code looks for a dash):

Private Sub Command1_Click()
Dim dashplace%, length%
For I% = 0 To File1.ListCount
FLIName = File1.List(I%) 'the text of the whole line
dashplace% = InStr(FLIName, "-") 'the position of the dash
length% = Len(FLIName) 'length of the whole line
If dashplace% = 0 Then
If FLIName <> "" Then
Text1 = FLIName & " is an invalid entry."
End If
Else:
Aname = Mid(FLIName, 1, dashplace% - 1) 'Artist's name
If LetterSort = "XX" Then
NameOfSong = Mid(FLIName, dashplace% + 1, length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab &
Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
TextGrid.ColAlignment(2) = 0
Else
Select Case Text2.Text
Case Is = "View By Artist"
If Mid(Aname, 1, 1) = LetterSort Then
NameOfSong = Mid(FLIName, dashplace% + 1, length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab
& Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If

Case Is = "View By Title"
NameOfSong = Mid(FLIName, dashplace% + 1, length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
If LetterSort <> "XX" Then 'show only a particular
letter
If Mid(NameOfSong, 1, 1) = LetterSort Then
TextGrid.AddItem Aname & vbTab & NameOfSong &
vbTab & Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If
End If
End Select
End If
End If
Next I%

End Sub

This code works fine, and fills the MSFlexGrid with the data I want, but I
have absolutely no idea how to print it. I've looked through all the
manuals I have and nothing seems to work. If I use "Printer.print TextGrid"
it only prints the first column, first row of data (there are two columns,
one for artist the other for song name). Is there a way to print this
directly to a printer or to export it to a Word for Windows document or a
text document or anything?

Phil Benson
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You must set up a loop looking at each row and each column, then print
that "cell" data.
Use the .rows (to get number of rows), .row (to set the row you are
on, and .col (to set the column you are on) methods. The .text method
tells you the text in the "cell". Then Print #x, .text; for each
column, ending the last column without a semi-colon (to get a new
line).

Example (I have separated columns on the printout using the TAB
command):

Dim X%

For X% = 0 To grdOutput.Rows - 1
grdOutput.ROW = X%
grdOutput.col = 1

Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text
Next X%
--
---
Allen

Free astrology software at:
http://www.astrowin.org

"MouseHart" <Mo*******@trap.net> wrote in message
news:9j********************@news4.srv.hcvlny.cv.ne t...
I've written a simple program in VB 6.0 to list all my MP3 files. To show them on the screen I used an MSFlexGrid named TextGrid (which is not
associated with any table or text file) in the following code run by a button (the files are all in the format "Artist - Name Of Song" in their directories, which is why the code looks for a dash):

Private Sub Command1_Click()
Dim dashplace%, length%
For I% = 0 To File1.ListCount
FLIName = File1.List(I%) 'the text of the whole line
dashplace% = InStr(FLIName, "-") 'the position of the dash
length% = Len(FLIName) 'length of the whole line
If dashplace% = 0 Then
If FLIName <> "" Then
Text1 = FLIName & " is an invalid entry."
End If
Else:
Aname = Mid(FLIName, 1, dashplace% - 1) 'Artist's name
If LetterSort = "XX" Then
NameOfSong = Mid(FLIName, dashplace% + 1, length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab & Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
TextGrid.ColAlignment(2) = 0
Else
Select Case Text2.Text
Case Is = "View By Artist"
If Mid(Aname, 1, 1) = LetterSort Then
NameOfSong = Mid(FLIName, dashplace% + 1, length% - (dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab & Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If

Case Is = "View By Title"
NameOfSong = Mid(FLIName, dashplace% + 1, length% - (dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
If LetterSort <> "XX" Then 'show only a particular letter
If Mid(NameOfSong, 1, 1) = LetterSort Then
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab & Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If
End If
End Select
End If
End If
Next I%

End Sub

This code works fine, and fills the MSFlexGrid with the data I want, but I have absolutely no idea how to print it. I've looked through all the manuals I have and nothing seems to work. If I use "Printer.print TextGrid" it only prints the first column, first row of data (there are two columns, one for artist the other for song name). Is there a way to print this directly to a printer or to export it to a Word for Windows document or a text document or anything?

Phil Benson

Jul 17 '05 #2

P: n/a
Thank you very much. I will implement this and see what happens. I wonder
why the book I use for reference ("Visual Basic from the Ground Up") and
Microsoft's on-line help don't make this obvious. Maybe they figure no one
will ever need to print data.

"Woof-Woof" <ot*********@cox.net> wrote in message
news:sTjAc.4935$8r5.4687@fed1read03...
You must set up a loop looking at each row and each column, then print
that "cell" data.
Use the .rows (to get number of rows), .row (to set the row you are
on, and .col (to set the column you are on) methods. The .text method
tells you the text in the "cell". Then Print #x, .text; for each
column, ending the last column without a semi-colon (to get a new
line).

Example (I have separated columns on the printout using the TAB
command):

Dim X%

For X% = 0 To grdOutput.Rows - 1
grdOutput.ROW = X%
grdOutput.col = 1

Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text;
Print #1, Tab;

grdOutput.col = grdOutput.col + 1
Print #1, grdOutput.text
Next X%
--
---
Allen

Free astrology software at:
http://www.astrowin.org

"MouseHart" <Mo*******@trap.net> wrote in message
news:9j********************@news4.srv.hcvlny.cv.ne t...
I've written a simple program in VB 6.0 to list all my MP3 files.

To show
them on the screen I used an MSFlexGrid named TextGrid (which is not
associated with any table or text file) in the following code run by

a
button (the files are all in the format "Artist - Name Of Song" in

their
directories, which is why the code looks for a dash):

Private Sub Command1_Click()
Dim dashplace%, length%
For I% = 0 To File1.ListCount
FLIName = File1.List(I%) 'the text of the whole line
dashplace% = InStr(FLIName, "-") 'the position of the dash
length% = Len(FLIName) 'length of the whole line
If dashplace% = 0 Then
If FLIName <> "" Then
Text1 = FLIName & " is an invalid entry."
End If
Else:
Aname = Mid(FLIName, 1, dashplace% - 1) 'Artist's name
If LetterSort = "XX" Then
NameOfSong = Mid(FLIName, dashplace% + 1, length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong & vbTab

&
Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
TextGrid.ColAlignment(2) = 0
Else
Select Case Text2.Text
Case Is = "View By Artist"
If Mid(Aname, 1, 1) = LetterSort Then
NameOfSong = Mid(FLIName, dashplace% + 1,

length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
TextGrid.AddItem Aname & vbTab & NameOfSong

& vbTab
& Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If

Case Is = "View By Title"
NameOfSong = Mid(FLIName, dashplace% + 1,

length% -
(dashplace + 1) - 3)
If Mid(NameOfSong, 1, 1) = " " Then
NameOfSong = Mid(NameOfSong, 2, 255)
End If
If LetterSort <> "XX" Then 'show only a

particular
letter
If Mid(NameOfSong, 1, 1) = LetterSort Then
TextGrid.AddItem Aname & vbTab &

NameOfSong &
vbTab & Dir1.Path
TextGrid.ColAlignment(0) = 0
TextGrid.ColAlignment(1) = 0
End If
End If
End Select
End If
End If
Next I%

End Sub

This code works fine, and fills the MSFlexGrid with the data I want,

but I
have absolutely no idea how to print it. I've looked through all

the
manuals I have and nothing seems to work. If I use "Printer.print

TextGrid"
it only prints the first column, first row of data (there are two

columns,
one for artist the other for song name). Is there a way to print

this
directly to a printer or to export it to a Word for Windows document

or a
text document or anything?

Phil Benson


Jul 17 '05 #3

P: n/a
I had to modify your code as follows in order to make it work:

Dim X%

For X% = 0 To TextGrid.Rows - 1
TextGrid.Row = X%
TextGrid.Col = 0
Printer.Print , TextGrid.Text;
TextGrid.Col = TextGrid.Col + 1
Printer.Print , TextGrid.Text
Next X%

For some reason, if I use the line
Print #1, TextGrid.text;
it gives me a "Bad File Name or Number" error on that line, and yet it shows
the correct value for TextGrid.text. The bright side is that it actually
prints, which is more than it did before.

Using Printer.Print seems to correct the error, and the Tab call makes it
somewhat too wide for my purposes, so I removed that. All that being said,
it prints fine except that every few lines the alignment is screwy. For
example, it will read:

The Beatles Help
The Doors The End
Paul Newman Plastic Jesus

Note that the song "Plastic Jesus" is not aligned with the other two. I
have no idea why, and I'm not sure it's important to me at this point.

One last question: is it possible to just send the data to a text file and
pick up the text file with a word processing program from outside VB, or can
the data be sent directly to something like Word using the Microsoft Word
Document insertable object from the components list (either way would be
fine, although sending it directly to Word would be better)? Thanks for
bearing with me on this.

Phil Benson
Jul 17 '05 #4

P: n/a
>> One last question: is it possible to just send the data to a text
file and
pick up the text file with a word processing program from outside VB,
or can
the data be sent directly to something like Word using the Microsoft
Word
Document insertable object from the components list (either way would
be
fine, although sending it directly to Word would be better)? Thanks
for
bearing with me on this.

Yes. In general, here is how you write to a file:

Close #1
Open "nameoffile.txt" for Output As #1

'you can set up your loop in here - I only show one line of text being
printed to file
Print #1, TextGrid.Text

Close #1
I have never tried working with the Word object, but I don't see why
what you ask is not possible.

--
---
Allen

"MouseHart" <Mo*******@trap.net> wrote in message
news:D2*********************@news4.srv.hcvlny.cv.n et...
I had to modify your code as follows in order to make it work:

Dim X%

For X% = 0 To TextGrid.Rows - 1
TextGrid.Row = X%
TextGrid.Col = 0
Printer.Print , TextGrid.Text;
TextGrid.Col = TextGrid.Col + 1
Printer.Print , TextGrid.Text
Next X%

For some reason, if I use the line
Print #1, TextGrid.text;
it gives me a "Bad File Name or Number" error on that line, and yet it shows the correct value for TextGrid.text. The bright side is that it actually prints, which is more than it did before.

Using Printer.Print seems to correct the error, and the Tab call makes it somewhat too wide for my purposes, so I removed that. All that being said, it prints fine except that every few lines the alignment is screwy. For example, it will read:

The Beatles Help
The Doors The End
Paul Newman Plastic Jesus

Note that the song "Plastic Jesus" is not aligned with the other two. I have no idea why, and I'm not sure it's important to me at this point.
One last question: is it possible to just send the data to a text file and pick up the text file with a word processing program from outside VB, or can the data be sent directly to something like Word using the Microsoft Word Document insertable object from the components list (either way would be fine, although sending it directly to Word would be better)? Thanks for bearing with me on this.

Phil Benson

Jul 17 '05 #5

P: n/a
Thanks for your help. I'll give this a try also.

Yes. In general, here is how you write to a file:

Close #1
Open "nameoffile.txt" for Output As #1

'you can set up your loop in here - I only show one line of text being
printed to file
Print #1, TextGrid.Text

Close #1
I have never tried working with the Word object, but I don't see why
what you ask is not possible.

--

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.