[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Define Public Variable Correctly

Posted on 2012-03-21
1
Medium Priority
?
240 Views
Last Modified: 2012-03-25
I just finished integrating Motorola's SDK into my vb.net 2010 project.  The SDK depends on a driver to be installed on the computer which maintains the interaction between the vb.net program and the scanner.  My problem is that this program is used by people who will not be using a scanner, so now the program is throwing an error because the referenced object is not present on the computer.  I assume the variable definition of the scanner classs is where it causes the problem.  Is there a way to catch the error thrown by this since it's outside of a sub or function?  Thanks for any help.
0
Comment
Question by:rcblevins
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 2000 total points
ID: 37750780
If you defined your variable as a "global" variable, a Public variable in a module, I do not think that you can do that.

Personnally, I would design my application in another way.

If you know beforehand which users have a scanner and which don't, you could use conditional compilation or partial classes to create 2 versions of the application.

As a simple introduction, let's say that conditional compilation has portions of code compiling according to a configuration that you add to the Release/Debug configurations from which you can select between 2 modes of compiling. You could add a third and end up with code like the following:
#If NoScanner
    Public ScannerVariable As ScannerClass
#End If

#If NoScanner
   mnuScan.Visible=False
#End If¨

Open in new window

Just by switching your configuration between Release and NoScanner, you would end up with 2 different executables from the same source code. One for some user, another one for others.

Another approach would be to use partial classes. This is a technique that enables you to split a class (a form is a class) in many files. Your classes and forms would end up splitted in 2 files having the following structure:

File 1:
Class YourClass
   'Code available to everybody
End Class

Open in new window

File 2:
Partial Class YourClass
   'Code available only to the users who have a scanner
End Class

Open in new window

You would have 2 projects. One with only File 1, for users who do not have a scanner. The other with all the files, for users who have a scanner. Each compilation would end up generating an application for a specific type or user.

If you do not know beforehand which users have the scanner libraries installed or not, then I would put all the code that deals with the scanners in a dll that would be distributed to everybody. Your application would reference that dll, not the scanner dll. It would thus be able to start even if the scanner classes are not available.

When the application launch, detect the presence of the scanner software, by looking at the presence of the necessary files, registry information or any mean available. If it is not present, then do not instantiate any of the classes in your library. It won't be loaded in memory and won't trigger the error you have now. You will then also be able to deactivate or make invisible any interface option dealing with the scanner.
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question