?
Solved

User Defined Types

Posted on 2001-07-02
12
Medium Priority
?
175 Views
Last Modified: 2012-06-27
Could someone please tell me what the following statement means and how can I get around it. I am trying to use the IsEmpty function on a user-defined type.

"Only User-Defined Types defined in Public Object modules can be coerced to or from a variant or passed to late-bound functions."

Here is my if statement I am trying to use:
If IsEmpty(strPMActivities) = False Then

My strPMActivities() as udtPMData is my user defined type and is declared with in a function and is passed to other functions.

Liz
0
Comment
Question by:eware
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246077
IsEmpty only returns meaningful information for variants.  UDT is not a variant, so find another way to figure out if it is initialized or not.
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6246157
could you post some more code where you use it?
0
 

Author Comment

by:eware
ID: 6246170
If IsEmpty(strPMActivities) = False Then
    For I = 1 To UBound(strPMActivities)
        Set lsvData = frmRunSchedule.lsvPMSchedule.ListItems.Add(, ,                strPMActivities(I).intPMID)
        With lsvData
            .SubItems(1) = strPMActivities(I).strMesaPMID
            .SubItems(2) = "SCHEDULED"
            .SubItems(3) = strPMActivities(I).strActName
        End With
    Next I
end if

Basically says if there is data in the array, do the for loop below. I have many udt's and have tried a function that will send me back an integer, 0 for no data and 1 for data, but I would need a function for each data type.

Liz
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Accepted Solution

by:
PaulHews earned 400 total points
ID: 6246182
>>>
Basically says if there is data in the array, do the for loop below. I have many udt's and have tried
a function that will send me back an integer, 0 for no data and 1 for data, but I would need a function
for each data type.
<<<

Use error trapping on Ubound

dim lngUBound as long

On Error resume next
lngUbound = Ubound(strPMActivities)


If err.Number = 0 then
   On Error Goto 0
   For I = 1 To lngUBound
       Set lsvData = frmRunSchedule.lsvPMSchedule.ListItems.Add(, ,                strPMActivities(I).intPMID)
       With lsvData
           .SubItems(1) = strPMActivities(I).strMesaPMID
           .SubItems(2) = "SCHEDULED"
           .SubItems(3) = strPMActivities(I).strActName
       End With
   Next I
end if
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246185
Might want to add this at the end

On Error Goto 0


Otherwise, error trapping still in effect if no data in array.
0
 

Author Comment

by:eware
ID: 6246240
Could I have multiple On Errors in a function/
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246250
You can't nest them if that's what you mean.
0
 

Author Comment

by:eware
ID: 6246255
What I meant by my previous question was I have On Error Goto Errorhandler as well. Is it possible to have multiple On Errors and it know which one to go to?
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 6246257
But you can temporarily change your default error handler to take something different...

On Error goto errHandler  'default error handling

....code and stuff

on error resume next  'change default handler
if err.number = 0
  ''blablabla
end if
on error goto errHandler  'turn default handler back on
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6246432
A little comment, what is strPMActivities? Array or UDT?
i missed something!
0
 

Author Comment

by:eware
ID: 6246480
I am glad that someone knows how to catch these errors. It is really difficult when you can't find an answer in the help. It is alot of work because I have these ubounds everywhere, but If it does what I need it to do, I will use it. Thank you for your help.

Liz
0
 

Author Comment

by:eware
ID: 6246487
strPMActivities is a UDT.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

741 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question