I understand that the type structure is the ancestor of the class function. However coding a Type structure is quick, simple and easy. Thus I tried the following without success.
Working inside a class in VBa, I tried to return multiple variables from an internal function to another function within the class. I have tried to do that with a type element, however there is an internal conflict within the class function.
I have two questions:
1.) Are types not allowed in classes?
2.) What is a good practice method for returning multi-variable outputs from a function within a class?
Private Type checkResult
status As Boolean
errorp As String
End Type
Function CheckPTID(PTid As String) As checkResult
Dim plen As Boolean ' PT length
Dim numdash As Boolean ' numbers and dashes
Dim titles As Boolean ' Tiles correct
' initials
plen = False
numdash = False
titles = False
' Checks
If Len(PTid) = 8 Then plen = True
If InStr(PTid, "-") > -1 Then numdash = True
If (Left(PTid, 2) = "XP" Or Left(PTid, 2) = "XA") Then titles = True
' output
If (plen = False Or numbdash = False Or titles = False) Then
CheckPTID.status = False
If Not plen Then CheckPTID.errorp = "** Error Name length incorrect:" & PTid
If Not numdash Then CheckPTID.errorp = "** Error Name format incorrect:" & PTid
If Not titles Then CheckPTID.errorp = "** Error Name titles incorrect:" & PTid
Else
CheckPTID.status = True
CheckPTID.errorp = "N/A"
End If
End Function
Error given in above code is: User-defined type not defined. Thanks
EDIT:
To help with the understanding of the structure. The following is shown :
Class
|--Properties
|--Function: CheckPTID
|--Type: checkResult
The real question is, how does one use the type function directly in a class without creating a new class.
public status as Booleanandpublic errorp as stringin a classcheckResultYou can create Private typesPrivate(and correct thenumbdashtypo) it should work.SuborFunctionbyref (wich is default), and modifying them within thatSuborFunction.