.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 10th, 2012, 03:00 PM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
[VB.NET] Object ambiguity with classes in a namespace

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.
__________________
I'd rather teach you to fish than give you a fish. I reserve the right to also slap you with the fish.

Reply With Quote
  #2  
Old January 23rd, 2012, 12:02 PM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
I just gave up and turned off Option Explicit. I feel like less of a man.

Reply With Quote
  #3  
Old January 23rd, 2012, 01:52 PM
requinix's Avatar
requinix requinix is online now
Still alive
Dev Shed God 16th Plane (12500 - 12999 posts)
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,860 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 5 Days 5 h 27 m 13 sec
Reputation Power: 8977
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
Since you know the name and signature of the method, you can continue using reflection to call it. Something like
Code:
fileType.GetMethod("Initialize", New Type() { GetType(whatever the ThreadIndex is) }).Invoke(fileObj, New Object() { btConn.ThreadIndex })

Reply With Quote
  #4  
Old January 23rd, 2012, 04:59 PM
Tukaro's Avatar
Tukaro Tukaro is offline
Standing 3 feet to the left.
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Jan 2006
Location: USA
Posts: 1,435 Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level)Tukaro User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 3 h 49 m 16 sec
Reputation Power: 184
Send a message via AIM to Tukaro Send a message via MSN to Tukaro
I'll give that a shot, thanks!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > [VB.NET] Object ambiguity with classes in a namespace

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap