Rory,
It's really a long story (and several hundred lines of code) but I am trying to set a dozen or so extended printer settings (like NUP) which requires manipulating DEVMODE types. In my code there are 5 different DEVMODES based on Universal vs. PostScript and also Windows versions. Snippet of the code (reduced DEVMODES to 3 and features to 3 for ease of viewing) looks like this:
Option Base 1
Option Explicit
Private Type DEVMODE_A
'many more elements
dmOrientation As Integer
dmPaperSize As Integer
'many more elements
dmFormName As String * 32
'many more elements
End Type
Private Type DEVMODE_B
'many more elements
dmOrientation As Integer
dmPaperSize As Integer
'many more elements
dmFormName As String * 32
'many more elements
End Type
Private Type DEVMODE_C
'many more elements
dmOrientation As Integer
dmPaperSize As Integer
'many more elements
dmFormName As String * 32
'many more elements
End Type
Type TT
lTest As Long
End Type
Sub SetDevModebyType(Feature As Long, 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 lRet As Long
DMType = GetDevmodeType 'Returns 1,2 or 3
'Fill the correct DEVMODE based on DMType
Select Case DMType
Case 1
DEVMODE_A = GetDevModeA
Case 2
DEVMODE_B = GetDevModeB
Case 3
DEVMODE_C = GetDevModeC
End Select
'Apply the setting for the Feature in the right DEVMODE
Select Case Feature
Case DM_ORIENTATION
Select Case DMType
Case 1
DEVMODE_A.dmOrientation = Setting
Case 2
DEVMODE_B.dmOrientation = Setting
Case 3
DEVMODE_C.dmOrientation = Setting
End Select
Case DM_PAPERSIZE
Select Case DMType
Case 1
DEVMODE_A.dmPaperSize = Setting
Case 2
DEVMODE_B.dmPaperSize = Setting
Case 3
DEVMODE_C.dmPaperSize = Setting
End Select
Case DM_FORMNAME
Select Case DMType
Case 1
DEVMODE_A.dmFormName = Setting
Case 2
DEVMODE_B.dmFormName = Setting
Case 3
DEVMODE_C.dmFormName = Setting
End Select
End Select
Select Case DMType
Case 1
Call CopyMemory(yDevModeArr(1), DEVMODE_A, Len(DEVMODE_A))
Case 2
Call CopyMemory(yDevModeArr(1), DEVMODE_B, Len(DEVMODE_B))
Case 3
Call CopyMemory(yDevModeArr(1), DEVMODE_C, Len(DEVMODE_C))
End Select
End Sub
While this method works, what I am trying to avoid are the interior cases which have to be repeated for each feature. I was hoping there was a way (such as evaluate and replace) to replace each of these cases with a single line that would set the feature to the correct DEVMODE.
I had previously tried your type within a type method but that doesn't help with this particular issue.
Note: I played around with conditional compiling but that won't work as I don't know the printer driver type (and thus DEVMODE type) until well into program execution.
Thanks,
Bookmarks