-
Apr 2nd, 2012, 12:56 AM
#1
Thread Starter
Junior Member
Converting C# to VB.net
How can I convert these C# lines into VB.net:
Code:
usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
usbDevices.DeviceAttached += new EventHandler(usbDevices_DeviceAttached);
usbDevices.DeviceRemoved += new EventHandler(usbDevices_DeviceRemoved);
Is there a += operator in VB.net?
-
Apr 2nd, 2012, 01:05 AM
#2
Re: Converting C# to VB.net
Code:
usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB)
AddHandler usbDevices.DeviceAttached, New EventHandler(AddressOf usbDevices_DeviceAttached)
AddHandler usbDevices.DeviceRemoved, New EventHandler(AddressOf usbDevices_DeviceRemoved)
-
Apr 2nd, 2012, 01:11 AM
#3
Thread Starter
Junior Member
Re: Converting C# to VB.net
I Receive an error with the above code indicating that usbDevices_DeviceAttached and usbDevices_DeviceRemoved are undeclared. These two names are supposed to be the names of the handlers that are being created. They do not have any values.
-
Apr 2nd, 2012, 01:17 AM
#4
Re: Converting C# to VB.net
There must be something like
Code:
private void usbDevices_DeviceAttached(...
{
...
}
in the c# code you're converting. That's the event handler for the DeviceAttached event.
You should add this sub to your code in order for this to work:
Code:
Private Sub usbDevices_DeviceAttached(...
End Sub
-
Apr 2nd, 2012, 01:24 AM
#5
Thread Starter
Junior Member
Re: Converting C# to VB.net
I tried this instead
<code> AddHandler usbDevices_DeviceAttached, AddressOf usbDevices.DeviceAttached
AddHandler usbDevices_DeviceRemoved, AddressOf usbDevices.DeviceRemoved
</Code>
but I receive the error: "AddressOf operand must be the name of a method(without parenthesis)"
usbDevices.DeviceAttached() and usbDevices.DeviceRemoved() have the following signature:
(sender as object, e as system.eventargs)
These are functions that are being invoked from a dll:
imports CyUSB
Dim usbDevices As USBDeviceList 'USB device list
Dim myDevice As CyUSBDevice
-
Apr 2nd, 2012, 01:37 AM
#6
Thread Starter
Junior Member
Re: Converting C# to VB.net
Actually, I think you may be right. The function needs to be defined. here is an example:
Code:
void usbDevices_DeviceAttached(object sender, EventArgs e)
{
USBEventArgs usbEvent = e as USBEventArgs;
// Take some action
}
I can define this function but I don't know what USBEventArgs is. It is not defined in the dll.
-
Apr 2nd, 2012, 04:14 AM
#7
Re: Converting C# to VB.net
Load the working C# application in the VS IDE, press F2 to bring up the object browser and use that to search for USBEventArgs. You would be able to trace it from there to the namespace and even the assembly it belongs to.
-
Apr 2nd, 2012, 04:30 AM
#8
Re: Converting C# to VB.net
The USBeventArgs class should be defined in the same dll that your USBDeviceList class.
Just browse through this dll using the object browser.
-
Apr 4th, 2012, 12:02 AM
#9
Thread Starter
Junior Member
Re: Converting C# to VB.net
Thanks for the assistance. What is the VB equivalent of these lines:
Code:
USBDeviceList usbDevices = new USBDeviceList(CyConst.DEVICES_CYUSB);
CyUSBDevice StreamDevice = usbDevices["Cy Stream Device"] as CyUSBDevice;
The first line I am able to convert just fine: (usbDevices is already declared)
Code:
usbDevices = New USBDeviceList(CyConst.DEVICES_CYUSB)
I am not certain of how to create a new instance of streamDevice as a CyUSBDevice: (I already declared StreamDevice as a CyUSBDevice)
Code:
StreamDevice = usbDevices("Cy Stream Device") (as CyUSBDevice)
Last edited by mk48; Apr 4th, 2012 at 12:07 AM.
-
Apr 4th, 2012, 12:06 AM
#10
Re: Converting C# to VB.net
csharp Code:
CyUSBDevice StreamDevice = usbDevices["Cy Stream Device"] as CyUSBDevice;
vb.net Code:
Dim StreamDevice As CyUSBDevice = TryCast(usbDevices("Cy Stream Device"), CyUSBDevice)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|