Hello guys am having trouble returning udt from a class
see what i did below
i put this in a module
Code:
'// UDT TICKETS //
Public Type udtTicket
Ticket_id As String
Ticket_pass As String
sCost As Integer
Time As String
Validity As Integer
FromTime As String
ToTime As String
Created As Date
User As String
End Type
i put this in this code in class
Code:
'###################################
'# Retrive a ticket #
'###################################
Public Function GetTicket(id As Integer) As udtTicket
GetTicket = sAllTicket(id)
End Function
guys pls help me out
Programming is all about good logic. Spend more time here
The error is misleading. When talking about UDTs, UDTs could be passed from a compiled OCX, DLL but not from a module/class within your project. Just the way it is.
There are a few workarounds
1. Don't use a UDT, use a class where each class property is a UDT member, i.e., the class would have propeties of Ticket, Time, Validity, etc. Classes can be passed
2. It is possible to use CopyMemory to pass a UDT, however, since your UDT contains strings, a simple CopyMemory command really won't work. The workaround would be pretty much the same effort as #1 above.
3. The easiest method I think.
a. Declare a Public udt variable in your module, i.e., Public cachedUDT As udtTicket
:: this way you can access the public variable from anywhere in your project
b. In any function that should return a UDT, set the cachedUDT equal to what would be returned, i.e.
Code:
Public Sub GetTicket(id As Integer)
cachedUDT = sAllTicket(id)
End Function
c. In any function that should receive a UDT, set the cachedUDT also
Code:
... from within your form
GetTicket 123
cachedUDT.User = "LaVolpe"
UpdateTicket 123
' from within your class/module; wherever GetTicket method is...
Private Sub UpdateTicket(id As Integer)
sAllTicket(id) = cachedUDT
End Sub
Note: I see you are using strings for Date and Time members of the UDT. Recommend against that, recommend using either Date variable types or Double.
Edited & FYI: The error does won't occur if the methods were private vs public, but of course, being private the scope of the routines would be limited to that specific class/module.
Last edited by LaVolpe; Jul 11th, 2009 at 08:47 AM.
Insomnia is just a byproduct of, "It can't be done"
If you declare a class sub/function/property as Friend (rather than Public/Private) then it can pass UDT's declared public in the project to other members of the project. Unlike Public procedures, Friend procedures are not visible to the controllers of a project.
i declared the UDT in a module in the active x dll and still wont work. when i run, i get a user define type not defined for this
Code:
Friend Function GetTicket(id As Integer) As udtTicket
GetTicket = sAllTicket(id)
End Function
You may have one issue or two.
1. If the UDT is to be passed to other modules/classes within your DLL from the DLL, then using Friend function or the public varaible workaround I described should do the trick.
2. If you want to pass the UDT from the DLL to the project hosting your DLL and vice versa, then I believe you can do that via a Public function but, the UDT must be declared Public in the active-x class vs the module. Worth a try.
Insomnia is just a byproduct of, "It can't be done"