Quantcast
Channel: VBForums - API
Viewing all articles
Browse latest Browse all 168

Conditional Compilation for Declare Statements

$
0
0
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:
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

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

Viewing all articles
Browse latest Browse all 168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>