I'm writing a program that works with a 3rd-party .NET library. The COM allows for an interface between .NET (or COM) programs and a proprietary format used by an accounting program.
Sadly, the documentation, despite being over 200 pages, is sorely lacking when it comes to explaining a lot of the basics, and much of the code is counter-intuitive. (For instance: to search for a specific entry by a term, you first have to include the term into a "key buffer" by using one of five functions based on the term's type, then make another call to a different function on a different class object with the parameter with what index (read: column) to use.) So I am trying to write my own middle-man class that will make the program not only easier to code, but also more reader-friendly should someone else have to take over my code in the future.
The namespace itself contains about 50 classes, most of which are related to one exact file in the accounting software; while these all share one or two basic functions, they all have different properties to align with each column in the files. I'm trying to make my middleware extensible for the future (in case the library itself or the accounting software changes), and in any case I really don't feel like writing 50 classes, one for each file.
I'm trying to pass an ambiguous object type containing one of these file classes to my function, which then assigns the type to a local variable. The actual properties of the class in question don't matter, as the variable will be manipulated at the top level (or is that bottom?). I have
Option Explicit On, and while turning that off might at least fix the nagging, I fear it won't take care of the errors that they could cause at runtime.
The Class Code:
Code:
.NET
Public Class MiddleWare
Private oConn As New ConnLibrary.LibraryAccessClass
Private oFile As New Object
Public Sub New(ByVal filename As String, ByVal fileType As Type)
Status = btConn.btOpen(mCompanyPath & "\" & filename, pcReadWrite)
If Status <> bts.OK Then
Throw FileAccessError(Status)
End If
fileObj = Activator.CreateInstance(fileType)
fileObj.Initialize(btConn.ThreadIndex)
End Sub
End Class
The calling code:
Code:
.NET
Dim fileAccess As New MiddleWare("filename.dat",GetType(ConnLibrary.FileInQuestion))
.Initialize is one of the few methods that are in all relevant classes. But, since fileObj does not have a defined type at compile time, Option Explicit throws a fit for .Initialize. Is there a way around this without turning off Option Explicit? I find it useful for debugging, and don't really trust that those who take over for me once I'm gone will understand enough to be safe without it.