Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Event firing all the time
Message
De
13/03/2003 11:34:18
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Titre:
Event firing all the time
Divers
Thread ID:
00765419
Message ID:
00765419
Vues:
101
Hello all, I downloaded some C# code from the web that activates the scanner on my PDA. When I ran the app, an event called ScannerEvent would fire whenever the scanner scanned an item. I took out the result form in the C# program and compiled to the rest of the code into a class library. I imported the library into my vb.net app. I took the code in the C# form and converted it to VB code to use in my result form. I notice a big difference. The scannerEvent is firing all the time. I don't know if this is just how the VB.NET side works or if I messed up in converting the code. Below is the code for both C# and VB. I appreciate the help. Thank you.

C# Code
using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Text;
using SmartMasrhal;
using Corrigo.CorrigoNet.CorrigoNetToGo;
using Corrigo.Components;


namespace ScanTest
{
///
/// Summary description for Form1.
///

public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private SymbolScanner scanner;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
if ( SymbolScanner.IsSupported() )
{
ScannerInfo[] lst = SymbolScanner.GetScanners();
scanner = new SymbolScanner("SCN1:");
}

}
///
/// Clean up any resources being used.
///

protected override void Dispose( bool disposing )
{
scanner.Dispose();
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///

private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.textBox1 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(8, 64);
this.textBox1.Size = new System.Drawing.Size(224, 22);
this.textBox1.Text = "";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(8, 112);
this.textBox2.Size = new System.Drawing.Size(224, 22);
this.textBox2.Text = "";
//
// Form1
//
this.Controls.Add(this.textBox1);
this.Controls.Add(this.textBox2);
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.Text = "Barcode test";
this.Load += new System.EventHandler(this.Form1_Load);
this.Closed += new System.EventHandler(this.Form1_Closed);

}
#endregion

///
/// The main entry point for the application.
///


static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
scanner.ScannerEvent += new EventHandler(scanner_ScannerEvent);
}

private void scanner_ScannerEvent(object sender, EventArgs e)
{
SymbolScanner scanner = sender as SymbolScanner;
textBox1.Text = scanner.ScanData;
textBox2.Text = scanner.ScanSource;
System.Windows.Forms.MessageBox.Show("hello");
}

private void Form1_Closed(object sender, System.EventArgs e)
{
Dispose(true);
}
}


}


VB Code
Imports System
Imports System.Drawing
Imports System.Collections
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Text
Imports SmartMasrhal
Imports Corrigo.CorrigoNet.CorrigoNetToGo
Imports Corrigo.Components
Imports Microsoft.WindowsCE.Forms

Public Class frmSpecimen
Inherits System.Windows.Forms.Form
Public mstrBarCode As String
Public mbolFromRoutes As Boolean
Private scanner As SymbolScanner

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent() call
If (SymbolScanner.IsSupported()) Then
Dim lst As ScannerInfo() = SymbolScanner.GetScanners()
scanner = New SymbolScanner("SCN1:")
End If
End Sub

#End Region

Private Sub scanner_ScannerEvent(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim scanner As SymbolScanner = sender
Dim x As String
Dim y As String
x = Trim(scanner.ScanData)
y = Trim(scanner.ScanSource)
If Len(x) > 0 Or Len(y) > 0 Then
MsgBox(scanner.ScanData, MsgBoxStyle.Information)
MsgBox(scanner.ScanSource, MsgBoxStyle.Information)
Me.txtScanCode.Text = scanner.ScanSource
Me.txtScanCode.Refresh()
End If
Catch
MsgBox("Hello", MsgBoxStyle.Information)
End Try
End Sub

Private Sub frmSpecimen_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
LoadRoutes()
scanner = New SymbolScanner("SCN1:")
AddHandler scanner.ScannerEvent, AddressOf scanner_ScannerEvent
End Sub

Private Sub frmSpecimen_Disposed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Disposed
scanner.Dispose()
MyBase.Dispose(True)
sender = True
End Sub

End Class
Randy Belcher
AFG Industries, Inc.
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform