I have several User Defined Types (UDT) of different DEVMODE structures that I would like to declare a variable with conditionally based on passing a variable argument to a function. My test code looks like:
However, when I tested this code, no matter what DevModeType value I send to the function it always dimensions DM as the first UDT (DEVMODEPS500).
My question: Is it possible to dimension a variable conditionally based on a passed variable? If yes, how would I modify my code to achieve this?
Note: I cannot use the variant data type as it will not except a UDT.
Thanks,
Tom
Code:
Function TestConditionalCompile(DevModeType As Long) As Boolean
#If DevModeType = 1 Then
Dim DM As DEVMODEPS500
#ElseIf DevModeType = 2 Then
Dim DM As DEVMODEPS
#ElseIf DevModeType = 3 Then
Dim DM As DEVMODEUNI500
#ElseIf DevModeType = 4 Then
Dim DM As DEVMODEUNI
#Else
Dim DM As DEVMODE
#End If
'execution code goes here
End Function
My question: Is it possible to dimension a variable conditionally based on a passed variable? If yes, how would I modify my code to achieve this?
Note: I cannot use the variant data type as it will not except a UDT.
Thanks,
Tom