-
How can I print the contents of more than one combo box on the same line. I am trying this code, but it doesn't work. The text box array prints one tab apart on the same line, like its in columns. I need the combo boxes to do the same thing. This code just prints them down the left side. Excuse the screwy code, I have been trying everything I could think of.
Private Sub Combo1_KeyPress(Index As Integer, KeyAscii As Integer)
Dim p As Integer
p = Index
If KeyAscii = 13 Then
Combo1(p).AddItem (Combo1(p).Text)
Combo1(p).Text = ""
End If
End Sub
Private Sub cmdPrint_Click()
Dim x As Integer
Dim p As Integer
Dim i As Integer
Do Until x = Text1().Count
Print Text1(x).Text; vbTab; vbTab;
x = x + 1
Loop
Print
Do Until p = Combo1().Count
PrntCbo (p)
p = p + 1
Loop
End Sub
Private Function PrntCbo(Index As Integer)
Dim p As Integer
Dim i As Integer
p = Index
Do Until i = Combo1(p).ListCount
Print Combo1(p).List(i)
i = i + 1
Loop
End Function
-
Your code should work if you include the semi-colons as you did previously
Code:
Private Function PrntCbo(Index As Integer)
Dim p As Integer
Dim i As Integer
p = Index
Do Until i = Combo1(p).ListCount
Print Combo1(p).List(i);vbTab;vbTab;
i = i + 1
Loop
End Function
-
Closer
That is closer to what I need, but, if I have three items in the first combo box, I need them to print underneath each other like in a column, then move to the next column and print the contents of the next combo box in that column.
-
I think you'll need a more complicated routine for printing then. Maybe store the current X and Y positions on the printer and move back to them with each new combo, and just increment the CurrentX value. Either that, or cycle through all the combos like this:
Code:
Private Function PrntCbo(ByVal fIndex as Integer, ByVal eIndex as Integer)
Dim BaseLoop as Integer
Dim SubLoop as Integer
Dim maxCount as Integer
Dim cStr as String
'Work out what the longest Combo List is
maxCount=-1
For BaseLoop = fIndex to eIndex
If Combo1(BaseLoop).ListCount>maxCount Then
maxCount=Combo1(BaseLoop).ListCount
End If
Next BaseLoop
'Now build the Printer Strings
For BaseLoop = 0 to maxCount
cStr=""
For SubLoop = fIndex to eIndex
if Combo1(SubLoop).List(BaseLoop)="" Then
cStr=cStr & Combo1(SubLoop).List(BaseLoop)
End If
cStr=cStr & vbTab & vbTab
Next SubLoop
Print cStr
Next BaseLoop
End Function
-
finding longest combo
I can use the names of the comboboxes to get it to work.
I need to figure out which combo has the highest listcount to set my iterations. I can't figure out how to do it. I tried to work it out with this. In the function it sets a number to max, but I don't know how to retrieve the number. Can anyone help?
GetLong (max)
Do Until i = max
Print Combo1(0).List(i); vbTab; vbTab; Combo1(1).List(i); _
vbTab; vbTab; Combo1(2).List(i)
i = i + 1
Loop
End Sub
Private Function GetLong(ByVal max As Integer) As Integer
Dim BaseLoop As Integer
Dim SubLoop As Integer
Dim fIndex, eIndex As Integer
max = -1
For BaseLoop = fIndex To eIndex
If Combo1(BaseLoop).ListCount > max Then
max = Combo1(BaseLoop).ListCount
End If
Next BaseLoop
End Function
-
Sorry Kokopeli, Those comments I put in my code referred to what the code was about to do, rather than what you still needed to do. The routine should work as it currently is in your code. All you should have to change is the routine which calls the function.
-
Still confused
here is my print sub.
Private Sub cmdPrint_Click()
Dim x As Integer
Dim p As Integer
Dim i As Integer
Dim g As Integer
Dim max As Integer
Do Until x = Text1().Count
Print Text1(x).Text; vbTab; vbTab;
x = x + 1
Loop
Print
GetLong (max)
Do Until i = max
Print Combo1(0).List(i); vbTab; vbTab; Combo1(1).List(i); _
vbTab; vbTab; Combo1(2).List(i)
i = i + 1
Loop
End Sub
I just need to figure out how to get max to equal the max in the function.
-
Sorry if my reply was a little cryptic...
Paste my function into your project
Your function should be changed to the following:
Code:
Private Sub cmdPrint_Click()
Dim x As Integer
Do Until x = Text1().Count
Print Text1(x).Text; vbTab; vbTab;
x = x + 1
Loop
Print
PrntCbo(0,2)
End Sub
-
highest count
It still didn't work. Is there a way to find the highest listcount.
-
Sorry again Kokopeli. That will teach me to enter a whole routine in this window instead of testing it in VB first.
The prntCbo function I gave you earlier won't work. Here's a better one.
Code:
Private Function PrntCbo(ByVal fIndex As Integer, ByVal eIndex As Integer)
Dim BaseLoop As Integer
Dim SubLoop As Integer
Dim maxCount As Integer
Dim strC As String
'Work out what the longest Combo List is
maxCount = -1
For BaseLoop = fIndex To eIndex
If Combo1(BaseLoop).ListCount > maxCount Then
maxCount = Combo1(BaseLoop).ListCount
End If
Next BaseLoop
'Now build the Printer Strings
For BaseLoop = 0 To maxCount - 1
strC = ""
For SubLoop = fIndex To eIndex
If BaseLoop < Combo1(SubLoop).ListCount Then
strC = strC & Combo1(SubLoop).List(BaseLoop)
End If
strC = strC & vbTab & vbTab
Next SubLoop
Print strC
Next BaseLoop
End Function
In your function you use:
Code:
Private Sub cmdPrint_Click()
Dim x As Integer
Do Until x = Text1().Count
Print Text1(x).Text; vbTab; vbTab;
x = x + 1
Loop
Print
PrntCbo 0,2
End Sub
I've entered this code in VB and it works. Please try it.
-
Thanks
Thank you, it works, even with one combo empty. Just what I needed.