Results 1 to 7 of 7

Thread: [RESOLVED] VB6 Listbox Print Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Resolved [RESOLVED] VB6 Listbox Print Question

    I'm trying to print the contents of a listbox, but not getting them to print side by side. Also, it won't print until the application has been closed?? Any help would be greatly apprecited. Here's the code:

    VB Code:
    1. '*CMDPRINT_CLICK()*************************************************************
    2. 'NAME: cmdPrint_Click()
    3. 'DESC: Prints the contents of the listbox (lstFirstScreen).
    4. Private Sub cmdPrint_Click()
    5.     If (lstFirstScreen.ListCount > 0) Then
    6.         Dim lngIndex As Long
    7.         Dim count As Integer
    8.         Dim strArray() As String
    9.         Printer.FontSize = 11
    10.         'Printer.Print lstFirstScreen.List(0) & vbNewLine;
    11.         Printer.Print "--------------------------------------------------------" _
    12.             & "----------------------------------------------------------------" _
    13.             & "----------------------------"
    14.        
    15.         For lngIndex = 0 To lstFirstScreen.ListCount - 1
    16.             'Printer.Print lstFirstScreen.List(lngIndex) & vbNewLine;
    17.             strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
    18.             For count = LBound(strArray) To UBound(strArray)
    19.                 'MsgBox (lngIndex & ": " & strArray(count))
    20.                 Printer.Print strArray(count)
    21.                 Printer.Print vbTab
    22.             Next
    23.             Printer.Print vbNewLine
    24.         Next
    25.        
    26.         Printer.EndDoc
    27.     End If
    28. End Sub
    29. '*ENDOF*CMDPRINT_CLICK()*******************************************************

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VB6 Listbox Print Question

    VB Code:
    1. For lngIndex = 0 To lstFirstScreen.ListCount - 1
    2.             'Printer.Print lstFirstScreen.List(lngIndex) & vbNewLine;
    3.             strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
    4.             For count = LBound(strArray) To UBound(strArray)
    5.                 'MsgBox (lngIndex & ": " & strArray(count))
    6.                 Printer.Print strArray(count),
    7.             Next
    8.             Printer.Print
    9.         Next

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: VB6 Listbox Print Question

    Mange tak, but that looks just like my code other than the comma after strArray(count). Can you tell me what I was doing wrong?

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  4. #4
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: VB6 Listbox Print Question

    A print statement normally adds a newline after the text that is printed. However if you put a comma at the end it will insert a tab instead of a newline and the next print statement will print on the same line (after the tab). If you would use a semicolon instead of a comma, the next Print statement will print the text directly after the last printed text (no tab or line breaks are inserted).

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: VB6 Listbox Print Question

    mange tak

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    200

    Re: [RESOLVED] VB6 Listbox Print Question

    I have one last question about this topic, I hope at least. Whenever I added the items into the listbox it had to add tabs between them and sometimes I added two so that it would line up right. Is there a way to check for a tab on the item of the listbox so that I can skip it? Here's the code I have now:

    VB Code:
    1. '*CMDPRINT_CLICK()*************************************************************
    2. 'NAME: cmdPrint_Click()
    3. 'DESC: Prints the contents of the listbox (lstFirstScreen).
    4. Private Sub cmdPrint_Click()
    5.     If (lstFirstScreen.ListCount > 0) Then
    6.         Dim lngIndex As Long
    7.         Dim count As Integer
    8.         Dim strArray() As String
    9.         'Printer.FontSize = 11
    10.         For lngIndex = 0 To lstFirstScreen.ListCount - 1
    11.             If (lngIndex = 1) Then
    12.                 Printer.Print "--------------------------------------------------------" _
    13.                     & "----------------------------------------------------------------" _
    14.                     & "----------------------------"
    15.             End If
    16.             strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
    17.             For count = LBound(strArray) To UBound(strArray)
    18.                 If (strArray(count) = vbTab) Then
    19.                     count = count + 1
    20.                 End If
    21.                 Printer.Print strArray(count),
    22.             Next
    23.             Printer.Print
    24.         Next
    25.         Printer.EndDoc
    26.     End If
    27. End Sub
    28. '*ENDOF*CMDPRINT_CLICK()*******************************************************

    Nenio foriras ĝis ĝi havas instru ni kiu ni devas scii.

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: [RESOLVED] VB6 Listbox Print Question

    Since you split on tabs the array will not include the tab character. If you had two tabs after each other there would be an empty string between them so what you should do is to check if the array item contains any text.
    VB Code:
    1. For count = LBound(strArray) To UBound(strArray)
    2.     If Len(strArray(count)) > 0 Then 'if the array item contains any text then print it
    3.         Printer.Print strArray(count),
    4.     End If
    5. Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width