Home > Software engineering >  VBA, nested custom how to implement a hierarchical structure with the same child function declaratio
VBA, nested custom how to implement a hierarchical structure with the same child function declaratio

Time:11-14

This is a custom structure, nested TABLE () CJX (). CJ (). XH (), because from CJX, CJ, XH level these three layers, the corresponding code is similar, so I want to use a child function to simplify the code,
Need to pass the custom of the structure of the TYPE to function, to identify different levels to declare set data corresponding to different types, then the result of the different types of custom array returned to the main function,
Type TY_XH
The VALUE (1 To 7) As the Variant
The NAME As the Variant
GZMS () As TY_GZMS
End Type

Type TY_CJ
The VALUE (1 To 7) As the Variant
The NAME As the Variant
XH () As TY_XH
GZMS () As TY_GZMS
End Type

Type TY_CJX
The VALUE (1 To 7) As the Variant
The NAME As the Variant
CJ () As TY_CJ
GZMS () As TY_GZMS
End Type

Type TY_DJLX
The VALUE (1 To 7) As the Variant
The NAME As the Variant
CJX () As TY_CJX
GZMS () As TY_GZMS
End Type

Function A (TABLE AS TY_DJLX, LEVEL)
If LEVEL="2" Then
Dim SZ () As TY_CJX 'because the Dim statement directly, complains to repeat a statement, how to solve and realize the same function?
ElseIf LEVEL="3" Then
Dim SZ () As TY_CJ
ElseIf LEVEL="4" Then
Dim SZ () As TY_XH
End the If
.
A=SZ ()
End the Function

Sub TEST ()
Dim TABLE () AS TY_DJLX
.
TABLE (). CJX ()=A (TABLE, 2) 'this part code duplication, want to simplify
The TABLE (). CJX (). CJ ()=A (TABLE, 3)
The TABLE (). CJX (). CJ (). XH ()=A (TABLE, 4)
End Sub
` ` `

Novice small white, hope you teach a great god, thank you!

CodePudding user response:

Is simply how to realize dynamic statement struct...
  •  Tags:  
  • VBA