How to include sometimes

D

Darin

I have written software for the Symbol MC9060 which works great. It
requires a Symbol SDK loaded on the symbol unit for some barcode reader
specific DLLs.

Now, I need this to work on a non-symbol machine. I don't want to have
to have 2 versions of the source code, one that has the barcodereader
and one that doesn't. Can I do this.

Below is a sampling of code:

In the #Region " Windows Form Designer generated code"

Friend WithEvents BarcodeReader1 as symbol.barcode.barcodereader

me.barcodereader1=new symbol.barcode.barcodereader

Then in the MyBase.Load:

Barcodereader1.start

So, I have the barcodereader.start in an IF block verifing it is a
symbol device or not, but when I run the software on the intermec I get
an error: NullReferenceException on any program that has the
barcodereader loaded.

Is there a way to not even define the barcodereader if it isn't symbol.

Thanks.
 
G

Guest

PeterB,

What values would be assigned to the custom constants to prevent both code
blocks from being compiled? Another approach would be to create a generic
custom constant for the device and set it to the device manufacturer.

Example for build set to Symbol device:
Conditional compilation custom constant definition: DEVICEOEM="Symbol"

In code:
#If DEVICEOEM = "Symbol" Then
'This code block would be compiled since the constant is set to "Symbol"
#End If
#If DEVICEOEM = "Intermec" Then
'This code block would not be compiled since the constant is set to
"Symbol"
#End If

Example for build set to Intermec device:
Conditional compilation custom constant definition: DEVICEOEM="Intermec"

In code:
#If DEVICEOEM = "Symbol" Then
'This code block would not be compiled since the constant is set to
"Intermec"
#End If
#If DEVICEOEM = "Intermec" Then
'This code block would be compiled since the constant is set to "Intermec"
#End If

Just a thought,
Tom
 
P

PeterB

I'm not sure you can assign a value like that to Compilation Constants...
perhaps you can. In my example you would have three sets of Project
configuration. In the Conditional Compilation Constants field of the
different configurations you could have:

For Symbol: TRACE; SYMBOL
For Intermec: TRACE; INTERMEC
For None: TRACE

So to compile without any of the two makes you just don't define the
constant.

/ Peter
 
C

Chris Tacke, eMVP

Or better yet dynamically look for the right scanner DLL and load a scanning
assembly based on that so a single executable works on all devices,
otherwise you'll have a deployment support nightmare.

-Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top