Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Passing User Defined Type Array to Listbox

Trying to update some VBA I've developed to change a two dimensional array
to a custom data type as I've found it to be easier to work with the entire
array.

However, I ran into a problem when I tried to pass the array to a Listbox in
a userform.

With the array (Item) defined as a 2-d array the code

UserForm1.ListBox1.List = Item

works just fine and the array appears in the Userform.

However if I dim the "Item" array as a custom type I get the following error

"Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions"

Is there something I can do to make this work?

TIA

PC


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Passing User Defined Type Array to Listbox

Probably not.

But you don't show how your array is defined.

--
Regards,
Tom Ogilvy


"PC" wrote in message
...
Trying to update some VBA I've developed to change a two dimensional array
to a custom data type as I've found it to be easier to work with the

entire
array.

However, I ran into a problem when I tried to pass the array to a Listbox

in
a userform.

With the array (Item) defined as a 2-d array the code

UserForm1.ListBox1.List = Item

works just fine and the array appears in the Userform.

However if I dim the "Item" array as a custom type I get the following

error

"Only user-defined types defined in public object modules can be coerced

to
or from a variant or passed to late-bound functions"

Is there something I can do to make this work?

TIA

PC




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Passing User Defined Type Array to Listbox

Tom

Thanks for looking at this.

Here's what I have now (without the custom data type)

Public Sub Find()

'Search Macro to locate items in a list and return the result array to a
listbox.

Application.ScreenUpdating = False

Dim Ctr As Integer
Dim TestVal As String
Dim Item() As String

On Error GoTo Canceled 'Never been sure if this is the best way to handle
an error

UserForm4.Show

'compval is a public variable

If compval = "" Then
GoTo Canceled
End If

Worksheets("List").Activate
numrows = Range("list").Rows.Count 'list is a dynamic named range

Ctr = 0
For i = 1 To numrows 'all values are converted to lower case to
eliminate issues with case
TestVal = Evaluate("LOWER(OFFSET(A3," & i & ",0))")
If TestVal Like "*" & LCase(compval) & "*" Then
Ctr = Ctr + 1
End If
Next i

If Ctr = 0 Then
MsgBox "No Matching Products Found", vbOKOnly, "SELECTION"
GoTo Canceled

Else 'add items to the array
ReDim Item(1 To Ctr, 1 To 3) 'redim the item list based on the
number of items (I'd love to do this without counting the items first)
For i = 1 To numrows
TestVal = Evaluate("LOWER(OFFSET(A3," & i & ",0))")
If TestVal Like "*" & LCase(compval) & "*" Then
CtrA = CtrA + 1
Item(CtrA, 1) = Range("A3").Offset(i, 0)
Item(CtrA, 2) = Range("A3").Offset(i, 1)
Item(CtrA, 3) = Format(Range("A3").Offset(i, 2), "$#.00")
End If
Next i

End If


UserForm1.ListBox1.List = Item
UserForm1.Show

Worksheets("Form").Activate

' Find the next available row and then do stuff with the selection

Canceled:
Application.ScreenUpdating = True
End Sub




When I tried it with the custom type I used the following type declaration
at the beginning of the Module after the public variable declarations but
before any proceedures (I adjusted the references in the section where the
items are added to the array from "Item(Ctra, 1)" to "Item(Ctra).Name ...
and that did not error).

Type Listitem
Name as string
Description as string
Value as currency
End Type

Thanks for your always helpful input.

PC


"Tom Ogilvy" wrote in message
...
Probably not.

But you don't show how your array is defined.

--
Regards,
Tom Ogilvy


"PC" wrote in message
...
Trying to update some VBA I've developed to change a two dimensional

array
to a custom data type as I've found it to be easier to work with the

entire
array.

However, I ran into a problem when I tried to pass the array to a

Listbox
in
a userform.

With the array (Item) defined as a 2-d array the code

UserForm1.ListBox1.List = Item

works just fine and the array appears in the Userform.

However if I dim the "Item" array as a custom type I get the following

error

"Only user-defined types defined in public object modules can be coerced

to
or from a variant or passed to late-bound functions"

Is there something I can do to make this work?

TIA

PC






Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing an array in a user defined function Peter M Excel Programming 5 June 27th 08 10:45 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Word.Document - user defined type not defined jowatkins[_7_] Excel Programming 0 January 20th 04 08:46 AM
Passing an Array of User-Defined Type to an Argument of a Function Tushar Mehta[_6_] Excel Programming 0 August 17th 03 06:43 PM


All times are GMT +1. The time now is 08:02 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"