The best I can think of at the moment is to use classes as Norie suggested, which at least removes a lot of the Select Case coding. For example:
Class DM_A:
Option Explicit
Private dma As DEVMODE_A
Public Property Let dmOrientation(ByVal value As Integer)
dma.dmOrientation = value
End Property
Public Property Let dmPaperSize(ByVal value As Integer)
dma.dmPaperSize = value
End Property
'many more elements
Public Property Let dmFormName(ByVal value As String)
dma.dmFormName = value
End Property
Public Property Get DEVMODE() As DEVMODE_A
DEVMODE = dma
End Property
Public Property Let DEVMODE(value As DEVMODE_A)
dma = value
End Property
The other DEVMODEs would need similar classes.
Then your routine becomes something like:
Sub SetDevModebyType(Feature As String, Setting As Variant)
Dim DMType As Long
Dim DEVMODE_A As DEVMODE_A
Dim DEVMODE_B As DEVMODE_B
Dim DEVMODE_C As DEVMODE_C
Dim oDevModeA As DM_A
Dim oDevModeB As DM_B
Dim oDevModeC As DM_C
Dim lRet As Long
DMType = getDevModeType 'Returns 1,2 or 3
'Fill the correct DEVMODE based on DMType
Select Case DMType
Case 1
Set oDevModeA = New DM_A
DEVMODE_A = GetDevModeA
oDevModeA.DEVMODE = DEVMODE_A
'Apply the setting for the Feature in the right DEVMODE
CallByName oDevModeA, Feature, VbLet, Setting
Call CopyMemory(yDevModeArr(1), oDevModeA.DEVMODE, Len(oDevModeA.DEVMODE))
Case 2
Set oDevModeB = New DM_B
DEVMODE_B = GetDevModeB
oDevModeB.DEVMODE = DEVMODE_B
CallByName oDevModeB, Feature, VbLet, Setting
Call CopyMemory(yDevModeArr(1), oDevModeB.DEVMODE, Len(oDevModeB.DEVMODE))
Case 3
Set oDevModeC = New DM_C
DEVMODE_C = GetDevModeC
oDevModeC.DEVMODE = DEVMODE_C
CallByName oDevModeC, Feature, VbLet, Setting
Call CopyMemory(yDevModeArr(1), oDevModeC.DEVMODE, Len(oDevModeC.DEVMODE))
End Select
End Sub
Where you now pass the feature as a string:
Sub foo()
SetDevModebyType "dmOrientation", 5
End Sub
Would that help at all?
Bookmarks