473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How do I print MSFlexGrid data?

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
5 13343
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
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
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
>> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Schapopa | last post by:
I am using MS Access and VB 6.0 I am trying to create MSFlexGrid with the same data that I have in the Excel spreadshit, and that is: Jan03 Feb03 March03 Data1 2 3 4...
0
by: Ed | last post by:
Hi, I am using an MSflexgrid in my c# code. I have a strange problem. My MSflexgrid has only 1 column. Now the data in that column can be long. WIth just 1 column the MSflexgrid does not show...
1
by: David Sawyer | last post by:
I am attempting to capture data from the serial port, place that data into a MSFlexGrid and then use that data to parse out Lat/Lon to plot to a map. The problem I am having is when I attempt to...
1
by: Tulasi | last post by:
Hi all, This is very uregent requirement.Requirement is, i am using MSFlexgrid in vb.net .At the run time this grid contains some data items.Any body knows how to print these rows using...
1
by: Steven | last post by:
I develop the application which contains MSFlexGrid to display data. When I try to fill the grid with the text data, I want to adjust the column width so that the width is adjusted to the maximum...
4
by: rekhasc | last post by:
hi.......... i just want to print the msflexgrid ................. instead of printing a form...... can any one help me plz............ i am using vb6.0 and the back end is ms access
2
smartchap
by: smartchap | last post by:
In VB6 in a form there are 10 labels and associated 10 textboxes and 2 MSFlexGrids. There are 5 columns in the first MSFGrid and 7 in the second MSFGrid. There are 3 rows in the first grid and 4 in...
2
by: JuAn2226 | last post by:
hi,I got few question here. Hope some one can me. plz help me i running out of time 1. how to make my msflexgrid to display data for every 5 min(especially the number car and average speed. ...
0
by: mahesh123 | last post by:
Hi Folks, How can i export the data from the MSFlexGrid to the MS Open Office Excel in VB 6.0? I Can Know how to export data from the MSFlexgrid to the MS Office Excel. Please Help me regarding...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.