How do I print MSFlexGrid data?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MouseHart

    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.AddIte m Aname & vbTab & NameOfSong & vbTab &
    Dir1.Path
    TextGrid.ColAli gnment(0) = 0
    TextGrid.ColAli gnment(1) = 0
    TextGrid.ColAli gnment(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.AddIte m Aname & vbTab & NameOfSong & vbTab
    & Dir1.Path
    TextGrid.ColAli gnment(0) = 0
    TextGrid.ColAli gnment(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.AddIte m Aname & vbTab & NameOfSong &
    vbTab & Dir1.Path
    TextGrid.ColAli gnment(0) = 0
    TextGrid.ColAli gnment(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.pr int 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


  • Woof-Woof

    #2
    Re: How do I print MSFlexGrid data?

    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:
    Free Astrology Software including Astro123, AstroWin, Vocation, Election Helper, SE_Aspectarian, AstrAstr, PopHR, ProgTran, AstroSrc, AstroClk, MatchMkr, and More


    "MouseHart" <MouseHart@trap .net> wrote in message
    news:9jiAc.1803 2$0b.9062582@ne ws4.srv.hcvlny. cv.net...[color=blue]
    > I've written a simple program in VB 6.0 to list all my MP3 files.[/color]
    To show[color=blue]
    > 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[/color]
    a[color=blue]
    > button (the files are all in the format "Artist - Name Of Song" in[/color]
    their[color=blue]
    > 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.AddIte m Aname & vbTab & NameOfSong & vbTab[/color]
    &[color=blue]
    > Dir1.Path
    > TextGrid.ColAli gnment(0) = 0
    > TextGrid.ColAli gnment(1) = 0
    > TextGrid.ColAli gnment(2) = 0
    > Else
    > Select Case Text2.Text
    > Case Is = "View By Artist"
    > If Mid(Aname, 1, 1) = LetterSort Then
    > NameOfSong = Mid(FLIName, dashplace% + 1,[/color]
    length% -[color=blue]
    > (dashplace + 1) - 3)
    > If Mid(NameOfSong, 1, 1) = " " Then
    > NameOfSong = Mid(NameOfSong, 2, 255)
    > End If
    > TextGrid.AddIte m Aname & vbTab & NameOfSong[/color]
    & vbTab[color=blue]
    > & Dir1.Path
    > TextGrid.ColAli gnment(0) = 0
    > TextGrid.ColAli gnment(1) = 0
    > End If
    >
    > Case Is = "View By Title"
    > NameOfSong = Mid(FLIName, dashplace% + 1,[/color]
    length% -[color=blue]
    > (dashplace + 1) - 3)
    > If Mid(NameOfSong, 1, 1) = " " Then
    > NameOfSong = Mid(NameOfSong, 2, 255)
    > End If
    > If LetterSort <> "XX" Then 'show only a[/color]
    particular[color=blue]
    > letter
    > If Mid(NameOfSong, 1, 1) = LetterSort Then
    > TextGrid.AddIte m Aname & vbTab &[/color]
    NameOfSong &[color=blue]
    > vbTab & Dir1.Path
    > TextGrid.ColAli gnment(0) = 0
    > TextGrid.ColAli gnment(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,[/color]
    but I[color=blue]
    > have absolutely no idea how to print it. I've looked through all[/color]
    the[color=blue]
    > manuals I have and nothing seems to work. If I use "Printer.pr int[/color]
    TextGrid"[color=blue]
    > it only prints the first column, first row of data (there are two[/color]
    columns,[color=blue]
    > one for artist the other for song name). Is there a way to print[/color]
    this[color=blue]
    > directly to a printer or to export it to a Word for Windows document[/color]
    or a[color=blue]
    > text document or anything?
    >
    > Phil Benson
    >
    >[/color]


    Comment

    • MouseHart

      #3
      Re: How do I print MSFlexGrid data?

      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" <otie_nospam@co x.net> wrote in message
      news:sTjAc.4935 $8r5.4687@fed1r ead03...[color=blue]
      > 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" <MouseHart@trap .net> wrote in message
      > news:9jiAc.1803 2$0b.9062582@ne ws4.srv.hcvlny. cv.net...[color=green]
      > > I've written a simple program in VB 6.0 to list all my MP3 files.[/color]
      > To show[color=green]
      > > 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[/color]
      > a[color=green]
      > > button (the files are all in the format "Artist - Name Of Song" in[/color]
      > their[color=green]
      > > 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.AddIte m Aname & vbTab & NameOfSong & vbTab[/color]
      > &[color=green]
      > > Dir1.Path
      > > TextGrid.ColAli gnment(0) = 0
      > > TextGrid.ColAli gnment(1) = 0
      > > TextGrid.ColAli gnment(2) = 0
      > > Else
      > > Select Case Text2.Text
      > > Case Is = "View By Artist"
      > > If Mid(Aname, 1, 1) = LetterSort Then
      > > NameOfSong = Mid(FLIName, dashplace% + 1,[/color]
      > length% -[color=green]
      > > (dashplace + 1) - 3)
      > > If Mid(NameOfSong, 1, 1) = " " Then
      > > NameOfSong = Mid(NameOfSong, 2, 255)
      > > End If
      > > TextGrid.AddIte m Aname & vbTab & NameOfSong[/color]
      > & vbTab[color=green]
      > > & Dir1.Path
      > > TextGrid.ColAli gnment(0) = 0
      > > TextGrid.ColAli gnment(1) = 0
      > > End If
      > >
      > > Case Is = "View By Title"
      > > NameOfSong = Mid(FLIName, dashplace% + 1,[/color]
      > length% -[color=green]
      > > (dashplace + 1) - 3)
      > > If Mid(NameOfSong, 1, 1) = " " Then
      > > NameOfSong = Mid(NameOfSong, 2, 255)
      > > End If
      > > If LetterSort <> "XX" Then 'show only a[/color]
      > particular[color=green]
      > > letter
      > > If Mid(NameOfSong, 1, 1) = LetterSort Then
      > > TextGrid.AddIte m Aname & vbTab &[/color]
      > NameOfSong &[color=green]
      > > vbTab & Dir1.Path
      > > TextGrid.ColAli gnment(0) = 0
      > > TextGrid.ColAli gnment(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,[/color]
      > but I[color=green]
      > > have absolutely no idea how to print it. I've looked through all[/color]
      > the[color=green]
      > > manuals I have and nothing seems to work. If I use "Printer.pr int[/color]
      > TextGrid"[color=green]
      > > it only prints the first column, first row of data (there are two[/color]
      > columns,[color=green]
      > > one for artist the other for song name). Is there a way to print[/color]
      > this[color=green]
      > > directly to a printer or to export it to a Word for Windows document[/color]
      > or a[color=green]
      > > text document or anything?
      > >
      > > Phil Benson
      > >
      > >[/color]
      >
      >[/color]


      Comment

      • MouseHart

        #4
        Re: How do I print MSFlexGrid data?

        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


        Comment

        • Woof-Woof

          #5
          Re: How do I print MSFlexGrid data?

          >> 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" <MouseHart@trap .net> wrote in message
          news:D2tAc.4056 2$0b.11205079@n ews4.srv.hcvlny .cv.net...[color=blue]
          > 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[/color]
          it shows[color=blue]
          > the correct value for TextGrid.text. The bright side is that it[/color]
          actually[color=blue]
          > prints, which is more than it did before.
          >
          > Using Printer.Print seems to correct the error, and the Tab call[/color]
          makes it[color=blue]
          > somewhat too wide for my purposes, so I removed that. All that[/color]
          being said,[color=blue]
          > it prints fine except that every few lines the alignment is screwy.[/color]
          For[color=blue]
          > 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[/color]
          two. I[color=blue]
          > have no idea why, and I'm not sure it's important to me at this[/color]
          point.[color=blue]
          >
          > One last question: is it possible to just send the data to a text[/color]
          file and[color=blue]
          > pick up the text file with a word processing program from outside[/color]
          VB, or can[color=blue]
          > the data be sent directly to something like Word using the Microsoft[/color]
          Word[color=blue]
          > Document insertable object from the components list (either way[/color]
          would be[color=blue]
          > fine, although sending it directly to Word would be better)?[/color]
          Thanks for[color=blue]
          > bearing with me on this.
          >
          > Phil Benson
          >
          >[/color]


          Comment

          • MouseHart

            #6
            Re: How do I print MSFlexGrid data?

            Thanks for your help. I'll give this a try also.
            [color=blue]
            >
            > 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.
            >
            > --
            >
            >[/color]


            Comment

            Working...