JDL129
asked on
I need help converting some vb.net code to C#.net code
I need to change this to C# and I need to know where to put it.
Public WithEvents UPED As New SIM.Charge
Is this the correct translation?
SIM.Charge UPED = new SIM.Charge();
When I run the code I get the error message below but the SIM.dll is in the path specified by the properties of the dll.
System.IO.FileNotFoundExce ption was unhandled
Message="Could not load file or assembly 'Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9 cd9fa' or one of its dependencies. The system cannot find the file specified."
Source="SIM"
FileName="Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9 cd9fa"
FusionLog="=== Pre-bind state information ===\r\nLOG: User = CAKPOSSERVER\\Jerry\r\nLOG : DisplayName = Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9 cd9fa\n (Fully-specified)\r\nLOG: Appbase = file:///C:/POSiTrackC19/PO SiTrackC/P OSiTrackC/ bin/Debug/ \r\nLOG: Initial PrivatePath = NULL\r\nCalling assembly : SIM, Version=2.0.3.5, Culture=neutral, PublicKeyToken=5456cc89cbc b6145.\r\n ===\r\nLOG : This bind starts in default load context.\r\nLOG: Using application configuration file: C:\\POSiTrackC19\\POSiTrac kC\\POSiTr ackC\\bin\ \Debug\\PO SiTrackC.v shost.exe. Config\r\n LOG: Using machine configuration file from C:\\Windows\\Microsoft.NET \\Framewor k\\v2.0.50 727\\confi g\\machine .config.\r \nLOG: Post-policy reference: Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9 cd9fa\r\nL OG: Attempting download of new URL file:///C:/POSiTrackC19/PO SiTrackC/P OSiTrackC/ bin/Debug/ Hid.Net.DL L.\r\nLOG: Attempting download of new URL file:///C:/POSiTrackC19/PO SiTrackC/P OSiTrackC/ bin/Debug/ Hid.Net/Hi d.Net.DLL. \r\nLOG: Attempting download of new URL file:///C:/POSiTrackC19/PO SiTrackC/P OSiTrackC/ bin/Debug/ Hid.Net.EX E.\r\nLOG: Attempting download of new URL file:///C:/POSiTrackC19/PO SiTrackC/P OSiTrackC/ bin/Debug/ Hid.Net/Hi d.Net.EXE. \r\n"
StackTrace:
at SIM.USB_HID_Driver.USBInte rface..cto r()
at SIM.USB_HID..ctor()
at SIM.Charge..ctor()
at POSiTrackC.frmCCMX..ctor() in C:\POSiTrackC19\POSiTrackC \POSiTrack C\frmCCMX. cs:line 15
at POSiTrackC.frmEntry.btnCre ditCard_Cl ick(Object sender, EventArgs e) in C:\POSiTrackC19\POSiTrackC \POSiTrack C\frmEntry .cs:line 1020
at System.Windows.Forms.Contr ol.OnClick (EventArgs e)
at System.Windows.Forms.Butto n.OnClick( EventArgs e)
at System.Windows.Forms.Butto n.OnMouseU p(MouseEve ntArgs mevent)
at System.Windows.Forms.Contr ol.WmMouse Up(Message & m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Contr ol.WndProc (Message& m)
at System.Windows.Forms.Butto nBase.WndP roc(Messag e& m)
at System.Windows.Forms.Butto n.WndProc( Message& m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.OnMessa ge(Message & m)
at System.Windows.Forms.Contr ol.Control NativeWind ow.WndProc (Message& m)
at System.Windows.Forms.Nativ eWindow.De buggableCa llback(Int Ptr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.Unsaf eNativeMet hods.Dispa tchMessage W(MSG& msg)
at System.Windows.Forms.Appli cation.Com ponentMana ger.System .Windows.F orms.Unsaf eNativeMet hods.IMsoC omponentMa nager.FPus hMessageLo op(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoopInner (Int32 reason, ApplicationContext context)
at System.Windows.Forms.Appli cation.Thr eadContext .RunMessag eLoop(Int3 2 reason, ApplicationContext context)
at System.Windows.Forms.Appli cation.Run (Form mainForm)
at POSiTrackC.Program.Main() in C:\POSiTrackC19\POSiTrackC \POSiTrack C\Program. cs:line 27
at System.AppDomain._nExecute Assembly(A ssembly assembly, String[] args)
at System.AppDomain.ExecuteAs sembly(Str ing assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.Hos tingProces s.HostProc .RunUsersA ssembly()
at System.Threading.ThreadHel per.Thread Start_Cont ext(Object state)
at System.Threading.Execution Context.Ru n(Executio nContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHel per.Thread Start()
InnerException:
Public WithEvents UPED As New SIM.Charge
Is this the correct translation?
SIM.Charge UPED = new SIM.Charge();
When I run the code I get the error message below but the SIM.dll is in the path specified by the properties of the dll.
System.IO.FileNotFoundExce
Message="Could not load file or assembly 'Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9
Source="SIM"
FileName="Hid.Net, Version=1.0.0.0, Culture=neutral, PublicKeyToken=784515207d9
FusionLog="=== Pre-bind state information ===\r\nLOG: User = CAKPOSSERVER\\Jerry\r\nLOG
StackTrace:
at SIM.USB_HID_Driver.USBInte
at SIM.USB_HID..ctor()
at SIM.Charge..ctor()
at POSiTrackC.frmCCMX..ctor()
at POSiTrackC.frmEntry.btnCre
at System.Windows.Forms.Contr
at System.Windows.Forms.Butto
at System.Windows.Forms.Butto
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Butto
at System.Windows.Forms.Butto
at System.Windows.Forms.Contr
at System.Windows.Forms.Contr
at System.Windows.Forms.Nativ
at System.Windows.Forms.Unsaf
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at System.Windows.Forms.Appli
at POSiTrackC.Program.Main() in C:\POSiTrackC19\POSiTrackC
at System.AppDomain._nExecute
at System.AppDomain.ExecuteAs
at Microsoft.VisualStudio.Hos
at System.Threading.ThreadHel
at System.Threading.Execution
at System.Threading.ThreadHel
InnerException:
ASKER
tgerbert!!
Thanks for the response unfortunately neither suggestion worked.:( Maybe I just don't know where to place them in the code.
Jerry
Thanks for the response unfortunately neither suggestion worked.:( Maybe I just don't know where to place them in the code.
Jerry
Unfortunately, there is NO direct C# equivalent for the VB.Net WithEvents mechanism.
In VB.Net, you can subscribe to an event for a variable declared as "WithEvents" by tagging a sub with a "Handles" clause.
To convert that to C# you would need to manually "wire up" the event to your desired method. This can be done either thru the IDE at design-time, or at run-time.
In VB.Net, you can subscribe to an event for a variable declared as "WithEvents" by tagging a sub with a "Handles" clause.
To convert that to C# you would need to manually "wire up" the event to your desired method. This can be done either thru the IDE at design-time, or at run-time.
I was joking about the semi-colon thing, "SIM.Charge UPED = new SIM.Charge();" is correct. ;)
The error message reads Could not load file or assembly 'Hid.Net..., which means either Hid.Net couldn't be loaded, or some other DLL that Hid.Net itself uses couldn't be loaded. Do you have a Hid.Net.Dll? Did you add it as a reference to your project?
Visual-Studio---Add-Reference.png
The error message reads Could not load file or assembly 'Hid.Net..., which means either Hid.Net couldn't be loaded, or some other DLL that Hid.Net itself uses couldn't be loaded. Do you have a Hid.Net.Dll? Did you add it as a reference to your project?
Visual-Studio---Add-Reference.png
Subscribing to events won't do any good until we've got all the necessary assembly references. :P
Please post the complete code here So that I can help you out better.. :)
ASKER
guys!! Thanks for your posts!!!
Attached is the code that I am trying to run. As you can see I have the SIM.dll in the using section and also have it in the references.
I am a very newbie in .Net.
This is another line of code that needs to be translated:
UPED = New SIM.Charge(cboPort.Text, Baud, Parity, databits, cboDevice.SelectedIndex, txtLogLevel.Text)
Where and how would declare UPED?
Thanks guys!!!
Jerry
Attached is the code that I am trying to run. As you can see I have the SIM.dll in the using section and also have it in the references.
I am a very newbie in .Net.
This is another line of code that needs to be translated:
UPED = New SIM.Charge(cboPort.Text, Baud, Parity, databits, cboDevice.SelectedIndex, txtLogLevel.Text)
Where and how would declare UPED?
Thanks guys!!!
Jerry
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using SIM;
namespace POSiTrackC
{
public partial class frmCCMX : Form
{
SIM.Charge UPED = new SIM.Charge();
public frmCCMX()
{
InitializeComponent();
}
private void btnRequestSwipe_Click(object sender, EventArgs e)
{
}
private void btnProcess_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
UPED.MxCommSetting = SIM.Charge.MxCommType.Serial;
UPED.Baud = "115200";
UPED.DataBits = "8";
UPED.Parity = "E";
UPED.ComPort = 5;
UPED.Timeout = 10000;
UPED.Device = SIM.Charge.DeviceType.ppdVerifone_Mx870;
Select Case UPED.InitalizePinPad;{
Case True;
MessageBox.show("PinPad Initialized");
lblPPStatus.Text = "PinPad initialized successfully";;
Case Else;
MessageBox.show("PinPad Initialize Failure");
lblPPStatus.Text = "PinPad initialize failure";
End Select;
}
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
THANKS FOR THE LINKS!!! If this is from Harding University, I went there in 64 and 65.
Thanks again,
Jerry
Thanks again,
Jerry
Your C# code to declare and instantiate the SIM.Charge object is correct. That error message would suggest your project is missing a reference - right click on your project, choose Add Reference, and add the DLL containing SIM.Charge to your project.