I'm having troubles passing an Array from user-defined Type to a Function:
Defined Type (in a standard Module):
Public Type JPrinters
Available() As String
Default As String
End Type
Function to make a list of all available printers (std Module):
Function ListPrinters() As JPrinters
Dim GetPrinters As Object: Set GetPrinters = CreateObject("WScript.Network").EnumPrinterConnections
Dim i As Integer
Dim j() As String 'Array of Printer Names
ReDim j(0 To GetPrinters.Count \ 2 - 1)
For i = 0 To UBound(j)
'Load this array element with the Name from the list
j(i) = GetPrinters.Item(i * 2 + 1)
Next i
Dim k As JPrinters
With k
.Available = j
.Default = Application.ActivePrinter
End With
ListPrinters = k
End Function
Sub to populate a ComboBox by an Array (which works fine, normally – std Module):
Sub PopulateComboBoxBy2DArray(Ctrl As Control, ByVal Source_1D_2D_Array As String, Optional DefaultValue As String)
Ctrl.List = Source_1D_2D_Array
If DefaultValue Then
Ctrl.Value = DefaultValue
End If
End Sub
Then I try to call everything on Workbook_Open:
Private Sub Workbook_Open()
Dim Prt As JPrinters
Prt = ListPrinters
PopulateComboBoxBy2DArray List1.PrinterList, Prt.Available, Prt.Default
End Sub
- All modules have
Option Explicitdefined.
And it just gives my Compile error: Type mismatch. I tried a lot but cannot figure out why it won't accept the Prt.Available Array. Any ideas?
(I will also be glad for any other suggestions regarding the code.)
Thank you,
J