[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:
'*CMDPRINT_CLICK()*************************************************************
'NAME: cmdPrint_Click()
'DESC: Prints the contents of the listbox (lstFirstScreen).
Private Sub cmdPrint_Click()
If (lstFirstScreen.ListCount > 0) Then
Dim lngIndex As Long
Dim count As Integer
Dim strArray() As String
Printer.FontSize = 11
'Printer.Print lstFirstScreen.List(0) & vbNewLine;
Printer.Print "--------------------------------------------------------" _
& "----------------------------------------------------------------" _
& "----------------------------"
For lngIndex = 0 To lstFirstScreen.ListCount - 1
'Printer.Print lstFirstScreen.List(lngIndex) & vbNewLine;
strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
For count = LBound(strArray) To UBound(strArray)
'MsgBox (lngIndex & ": " & strArray(count))
Printer.Print strArray(count)
Printer.Print vbTab
Next
Printer.Print vbNewLine
Next
Printer.EndDoc
End If
End Sub
'*ENDOF*CMDPRINT_CLICK()*******************************************************
Re: VB6 Listbox Print Question
VB Code:
For lngIndex = 0 To lstFirstScreen.ListCount - 1
'Printer.Print lstFirstScreen.List(lngIndex) & vbNewLine;
strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
For count = LBound(strArray) To UBound(strArray)
'MsgBox (lngIndex & ": " & strArray(count))
Printer.Print strArray(count),
Next
Printer.Print
Next
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?
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).
Re: VB6 Listbox Print Question
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:
'*CMDPRINT_CLICK()*************************************************************
'NAME: cmdPrint_Click()
'DESC: Prints the contents of the listbox (lstFirstScreen).
Private Sub cmdPrint_Click()
If (lstFirstScreen.ListCount > 0) Then
Dim lngIndex As Long
Dim count As Integer
Dim strArray() As String
'Printer.FontSize = 11
For lngIndex = 0 To lstFirstScreen.ListCount - 1
If (lngIndex = 1) Then
Printer.Print "--------------------------------------------------------" _
& "----------------------------------------------------------------" _
& "----------------------------"
End If
strArray = Split(lstFirstScreen.List(lngIndex), vbTab, -1, 1)
For count = LBound(strArray) To UBound(strArray)
If (strArray(count) = vbTab) Then
count = count + 1
End If
Printer.Print strArray(count),
Next
Printer.Print
Next
Printer.EndDoc
End If
End Sub
'*ENDOF*CMDPRINT_CLICK()*******************************************************
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:
For count = LBound(strArray) To UBound(strArray)
If Len(strArray(count)) > 0 Then 'if the array item contains any text then print it
Printer.Print strArray(count),
End If
Next