ag93 ag93 - 1 year ago 113
C# Question

Converting from c# to vb

I am working on developing a scanner application and the only examples i can find are in c#. i am having a problem converting this one line of code to vb form c#.

MyBarcode.OnScan += new Barcode2.OnScanHandler(myBarcode_OnScan);

I have tried messing with delegates in vb but not 100% sure on how they work.

The example code is below to show what the variables are.

Barcode2 MyBarcode = new Barcode2();
// Submit an asynchronous scan (single read per call).
// Or, submit an asynchronous buffered scan call (read continuously until the buffered scanning is stopped).
// Register a scan event handler to the barcode object
MyBarcode.OnScan += new Barcode2.OnScanHandler(myBarcode_OnScan);

// Register a status event handler to the barcode object
MyBarcode.OnStatus += new Barcode2.OnScanHandler(myBarcode_OnStatus);


// Issue an Asynchronous scan that calls back to an event delegate when a trigger is pulled
Results sd = MyBarcode.Scan();


// The scan event Handler that gets called after a trigger is pulled a scan has been made. In the buffered mode scanning, the ScanDataCollection object may contain more than one set of data.
void myBarcode_OnScan(ScanDataCollection sd)
// If the asynchronous scanning is done in the buffered mode, there may be more than one scanned data in the collection
foreach (ScanData data in sd)
if (data.Result == Results.SUCCESS)
textBox.Text = data.Text;

// The status event Handler that gets called after the status of the scanner device is changed.
void myBarcode_OnStatus(StatusData statusData)
switch (statusData.State)
case States.IDLE:
statusBar.Text = "Press trigger to scan";
case States.READY:
statusBar.Text = "Aim at barcode to scan";


This code was pulled out of the Enterprise Mobility Developer toolkit for Motorola mobile devices. Any help would be appreciated.

Answer Source

From your comment it seems that you are adding an empty parameter list to the AddHandler method reference - don't do that - this is how your AddHandler statements should look:

AddHandler MyBarcode.OnScan, AddressOf myBarcode_OnScan

AddHandler MyBarcode.OnStatus, AddressOf myBarcode_OnStatus