I want to create a method that is common to both a desktop and a Web app. It needs to receive as a parameter either a ListBox (from within a desktop app) or a WebListBox (from within a WebApp). Obviously I cannot pass it as ListBox/WebListBox else it doesn’t compile.
I have tried passing it as a Variant and as an Object, but seem unable to access it within the method. Inside the method I have:
[code]#if targetdesktop
Dim tempListBox As ListBox
If listObject IsA ListBox then
tempListBox = listObject 'this is the error
do stuff with tempListBox
end if #elseif targetweb
#endif
[/code]
so the code doesn’t clash within the method.
I then tried to Dim a new ListBox/WebListBox within each #target area, but seem unable to assign the passed Object to the newly Dimmed variable. What is the right way to do this kind of thing?!
I passed the ‘listbox’ (ListBox or WebListBox) as a parameter myWebListBox As Object.
Then divided the code into: #if TargetDesktop then
#elseif TargetWeb then
#endif
Within each of the two sections I created a new ListBox (or WebListBox) then worked on that e.g.
Dim tempListBox As WebListBox
if myWebListBox IsA WebListBox then
tempListBox = WebListBox(myWebListBox)
'here is my code to work on tempListBox
end if
I now have one method for both desktop and web apps, but I have duplicate code within this method.