Skip to content

Instantly share code, notes, and snippets.

@1504168
Created May 31, 2022 18:35
Show Gist options
  • Save 1504168/2acdb7b69e6c70c8f08c7b2bb8f8dd5b to your computer and use it in GitHub Desktop.
Save 1504168/2acdb7b69e6c70c8f08c7b2bb8f8dd5b to your computer and use it in GitHub Desktop.
Property Code Generator from Variable declaration line
PROPERTYCODEGENERATOR = LAMBDA(VariableDeclarationLine,[IsOnlyGetter],LET(
SplitVariableDeclarationLine, TRANSPOSE(TEXTSPLIT(VariableDeclarationLine," ")),
VarNameIndex, MATCH("As",SplitVariableDeclarationLine,0)-1,
NonObjectDataType, {"Integer";"Long";"Single";"Double";"Currency";"Date";"String";"Boolean";"Decimal";"Byte";"LongLong"},
VarName, INDEX(SplitVariableDeclarationLine,VarNameIndex,1),
VarDataType, INDEX(SplitVariableDeclarationLine,VarNameIndex+2,1),
SetPrefix, IF(ISERROR(MATCH(VarDataType,NonObjectDataType,0)),"Set ",""),
WithoutSetGetPropertyBodyLine, VarName & " = This." & VarName,
PropertyAssignWithoutSet, "this." & VarName & " = "&VarName,
EndPropertyCode, "End Property",
GetPropertyStartLine, "Public Property Get " & VarName & " () As " & VarDataType,
IsPropertyLetNeeded, IF(VarDataType="Variant",TRUE,(TRIM(SetPrefix)<>"Set")),
IsPropertySetNeeded, IF(VarDataType="Variant",TRUE,(TRIM(SetPrefix)="Set")),
GetPropertyBodyLine, IF(VarDataType="Variant"," If IsObject(This." & VarName & ") Then" & CHAR(10) & " Set " & WithoutSetGetPropertyBodyLine & CHAR(10) & " Else" & CHAR(10) & " " & WithoutSetGetPropertyBodyLine & CHAR(10) & " End If"," " & SetPrefix & " " & WithoutSetGetPropertyBodyLine),
PropertyLetCode, IF(IsPropertyLetNeeded,"Public Property Let " & VarName & "( RHS As " & VarDataType & ")" & CHAR(10) & " " & PropertyAssignWithoutSet& CHAR(10) & EndPropertyCode,"" ),
PropertySetCode, IF(IsPropertySetNeeded,"Public Property Set " & VarName & "( RHS As " & VarDataType & ")" & CHAR(10) & " Set " & PropertyAssignWithoutSet& CHAR(10) & EndPropertyCode,"" ),
PropertyGetCode, GetPropertyStartLine & CHAR(10) & GetPropertyBodyLine & CHAR(10) & EndPropertyCode,
ValueAssigningProperty, IF(AND(IsPropertySetNeeded,IsPropertyLetNeeded),PropertyLetCode&CHAR(10)&CHAR(10)&PropertySetCode,IF(IsPropertyLetNeeded,PropertyLetCode,PropertySetCode)),
FinalPropertyCode, IF(IF(ISOMITTED(IsOnlyGetter),FALSE,IsOnlyGetter),PropertyGetCode,PropertyGetCode & CHAR(10) & CHAR(10) & ValueAssigningProperty),
FinalPropertyCode
)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment