W
Wanderer
I am writing a control (ocx) in VB6 to use in Excel VBA but I get Type Mismatch errors regarding my
UserDefinedType when using the control in VBA. For simplicity assume this code in the control...
'''''''''''''''''''''''''''''''BEGIN OCX CODE'''''''''''''''''''''''''''''
Public Type ToolStructure
Index as Integer
Diameter as Single
Description as String
End Type
Public Function GetToolInfo(Indx as Integer) as ToolStructure
If Indx < 1 then
GetToolInfo.Index = -1 'ACTS AS A 'NOT FOUND' FLAG
Else
GetToolInfo.Integer = Indx
GetToolInfo.Diameter = .5 'HARDCODED DATA FOR TESTING
GetToolInfo.Description = "Test"
End If
End Function
''''''''''''''''''''''''''''''''''''END OCX CODE'''''''''''''''''''''''''''''''''''''
Now I compile this and I can use it in VB apps with no problem. Sample code in the application would
look like this.
''''''''''''''''''''''''''''''''''BEGIN APPLICATION CODE''''''''''''''''''''''''''
Private Sub cmdTest_Click()
Dim X as TestOCX.ToolStructure
X = TestOCX1.GetToolInfo(3) 'HARDCODED DATA FOR TESTING
MsgBox X.Description
End Sub
''''''''''''''''''''''''''''''''''''END APPLICATION CODE'''''''''''''''''''''''''''''
This same code in VBA gives a "Type Mismatch" error on this line
X = TestOCX.GetToolInfo(3)
My actual UDT has many elements. I would hate to have to use a long list of
Property Get Diameter(ByVal Indx as Integer) as Single
Property Get Flutes(ByVal Indx as Integer) as Integer
Property Get Description(ByVal Indx as Integer) as String
etc etc
as it would be quite cludgy for the developer (not to mention decreased performance accessing
everything one by one). Can VBA just not handle UDT's or am I doing something wrong?
Thanks,
Robb
UserDefinedType when using the control in VBA. For simplicity assume this code in the control...
'''''''''''''''''''''''''''''''BEGIN OCX CODE'''''''''''''''''''''''''''''
Public Type ToolStructure
Index as Integer
Diameter as Single
Description as String
End Type
Public Function GetToolInfo(Indx as Integer) as ToolStructure
If Indx < 1 then
GetToolInfo.Index = -1 'ACTS AS A 'NOT FOUND' FLAG
Else
GetToolInfo.Integer = Indx
GetToolInfo.Diameter = .5 'HARDCODED DATA FOR TESTING
GetToolInfo.Description = "Test"
End If
End Function
''''''''''''''''''''''''''''''''''''END OCX CODE'''''''''''''''''''''''''''''''''''''
Now I compile this and I can use it in VB apps with no problem. Sample code in the application would
look like this.
''''''''''''''''''''''''''''''''''BEGIN APPLICATION CODE''''''''''''''''''''''''''
Private Sub cmdTest_Click()
Dim X as TestOCX.ToolStructure
X = TestOCX1.GetToolInfo(3) 'HARDCODED DATA FOR TESTING
MsgBox X.Description
End Sub
''''''''''''''''''''''''''''''''''''END APPLICATION CODE'''''''''''''''''''''''''''''
This same code in VBA gives a "Type Mismatch" error on this line
X = TestOCX.GetToolInfo(3)
My actual UDT has many elements. I would hate to have to use a long list of
Property Get Diameter(ByVal Indx as Integer) as Single
Property Get Flutes(ByVal Indx as Integer) as Integer
Property Get Description(ByVal Indx as Integer) as String
etc etc
as it would be quite cludgy for the developer (not to mention decreased performance accessing
everything one by one). Can VBA just not handle UDT's or am I doing something wrong?
Thanks,
Robb