4 Replies - 4177 Views - Last Post: 01 January 2010 - 05:25 PM Rate Topic: -----

#1 cxyuan85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-February 09

Error from Conversion from VB6 to VB express

Posted 31 December 2009 - 06:06 AM

Hi all,

I'm quite new to VB. I had open a VB6 file using VB express. Then some error arise after the conversion. Can someone help me with it and guide me along?
Thanks in advance.

1st error: Value of type 'Char' cannot be converted to 'Double' (Highlighted in Red)
Option Strict Off
Option Explicit On
Friend Class MainForm
	Inherits System.Windows.Forms.Form
	Private Const VendorID As Short = 6017
	Private Const ProductID As Short = 2000
	Private Const BufferInSize As Short = 8
	Private Const BufferOutSize As Short = 8
	Dim BufferIn(BufferInSize) As Byte
	Dim BufferOut(BufferOutSize) As Byte
	
	'UPGRADE_WARNING: Event Check1.CheckStateChanged may fire when form is initialized. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="88B12AE1-6DE0-48A0-86F1-60C0686C026A"'
	Private Sub Check1_CheckStateChanged(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Check1.CheckStateChanged
		Dim index As Short = Check1.GetIndex(eventSender)
		Dim LoopCheck As Object
		Dim PORTB As Byte
		PORTB = 0
		For LoopCheck = 0 To 7
			'UPGRADE_WARNING: Couldn't resolve default property of object LoopCheck. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6A50421D-15FE-4896-8A1B-2EC21E9037B2"'
			PORTB = PORTB + (Check1(LoopCheck).CheckState * (2 ^ LoopCheck))
		Next 
		BufferOut(1) = PORTB
		WriteSomeData()
	End Sub
	
	Private Sub Command1_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command1.Click
		Check1(7).CheckState = System.Windows.Forms.CheckState.Checked
	End Sub
	
	Private Sub Command2_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles Command2.Click
		Check1(7).CheckState = System.Windows.Forms.CheckState.Unchecked
	End Sub
	
	Private Sub MainForm_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
		ConnectToHID(Me.Handle.ToInt32) ' connect to HID
		Me.Text = "USB IO Control & Monitoring" ' Form title
		imgON.Visible = False ' Connect/Disconnect LED set of disconnect
		Dim index As Byte
		For index = 0 To 8 '
			BufferOut(index) = 0 ' set all array to '0'
		Next  '
		
		WriteSomeData() ' Send initial data (leds off, CCPs duty=0)
	End Sub
	
	Private Sub MainForm_FormClosed(ByVal eventSender As System.Object, ByVal eventArgs As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
		DisconnectFromHID() ' disconnect from the HID controller...
	End Sub
	
	Public Sub OnPlugged(ByVal pHandle As Integer)
		Dim DeviceHandle As Integer
		Dim VendorName As New VB6.FixedLengthString(15)
		'UPGRADE_NOTE: ProductName was upgraded to ProductName_Renamed. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="A9E4979A-37FA-4718-9994-97DD76ED70A7"'
		Dim ProductName_Renamed As New VB6.FixedLengthString(15)
		
		If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' Good one?
			DeviceHandle = hidGetHandle(VendorID, ProductID)
			hidGetVendorName(DeviceHandle, VendorName.Value, 255)
			hidGetProductName(DeviceHandle, ProductName_Renamed.Value, 255)
			imgON.Visible = True
		End If
	End Sub
	
	Public Sub OnUnplugged(ByVal pHandle As Integer)
		If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then ' good one?
			imgON.Visible = False
		End If
	End Sub
	
	Public Sub onchanged()
		Dim DeviceHandle As Integer
		DeviceHandle = hidGetHandle(VendorID, ProductID)
		hidSetReadNotify(DeviceHandle, True)
	End Sub
	
	Public Sub OnRead(ByVal pHandle As Integer)
		Dim index As Byte
		
		If hidRead(pHandle, BufferIn(0)) Then ' valid ReportID?
			If BufferIn(7) = 0 And BufferIn(8) = 0 Then
			Else
				For index = 1 To BufferInSize ' pass the whole array but skip (0)
					[color=#FF0000]If CDbl(Chr(BufferIn(index))) <> 0 Then ' valid data?[/color]
						'tUSBRx.Text = tUSBRx.Text & Chr(BufferIn(index)) ' Yes, send it to the TextBox
					End If
				Next 
			End If
		End If
	End Sub
	
	Public Sub WriteSomeData()
		BufferOut(0) = 0 ' first by is always the report ID
		BufferOut(6) = 0
		BufferOut(7) = 0
		BufferOut(8) = 0
		hidWriteEx(VendorID, ProductID, BufferOut(0)) ' send it
	End Sub
End Class



2nd Error: 'AddressOf' expression cannot be converted to 'Integer' because 'Integer' is not a delegate type. (Highlighted in Orange)
Option Strict Off
Option Explicit On
Module HIDDLLInterface
	' this is the interface to the HID controller DLL - you should not
	' normally need to change anything in this file.
	'
	' WinProc() calls your main form 'event' procedures - these are currently
	' set to..
	'
	' MainForm.OnPlugged(ByVal pHandle as long)
	' MainForm.OnUnplugged(ByVal pHandle as long)
	' MainForm.onchanged()
	' MainForm.OnRead(ByVal pHandle as long)
	
	
	' HID interface API declarations...
	Declare Function hidConnect Lib "mcHID.dll"  Alias "Connect"(ByVal pHostWin As Integer) As Boolean
	Declare Function hidDisconnect Lib "mcHID.dll"  Alias "Disconnect"() As Boolean
	Declare Function hidGetItem Lib "mcHID.dll"  Alias "GetItem"(ByVal pIndex As Integer) As Integer
	Declare Function hidGetItemCount Lib "mcHID.dll"  Alias "GetItemCount"() As Integer
	Declare Function hidRead Lib "mcHID.dll"  Alias "Read"(ByVal pHandle As Integer, ByRef pData As Byte) As Boolean
	Declare Function hidWrite Lib "mcHID.dll"  Alias "Write"(ByVal pHandle As Integer, ByRef pData As Byte) As Boolean
	Declare Function hidReadEx Lib "mcHID.dll"  Alias "ReadEx"(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean
	Declare Function hidWriteEx Lib "mcHID.dll"  Alias "WriteEx"(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean
	Declare Function hidGetHandle Lib "mcHID.dll"  Alias "GetHandle"(ByVal pVendoID As Integer, ByVal pProductID As Integer) As Integer
	Declare Function hidGetVendorID Lib "mcHID.dll"  Alias "GetVendorID"(ByVal pHandle As Integer) As Integer
	Declare Function hidGetProductID Lib "mcHID.dll"  Alias "GetProductID"(ByVal pHandle As Integer) As Integer
	Declare Function hidGetVersion Lib "mcHID.dll"  Alias "GetVersion"(ByVal pHandle As Integer) As Integer
	Declare Function hidGetVendorName Lib "mcHID.dll"  Alias "GetVendorName"(ByVal pHandle As Integer, ByVal pText As String, ByVal pLen As Integer) As Integer
	Declare Function hidGetProductName Lib "mcHID.dll"  Alias "GetProductName"(ByVal pHandle As Integer, ByVal pText As String, ByVal pLen As Integer) As Integer
	Declare Function hidGetSerialNumber Lib "mcHID.dll"  Alias "GetSerialNumber"(ByVal pHandle As Integer, ByVal pText As String, ByVal pLen As Integer) As Integer
	Declare Function hidGetInputReportLength Lib "mcHID.dll"  Alias "GetInputReportLength"(ByVal pHandle As Integer) As Integer
	Declare Function hidGetOutputReportLength Lib "mcHID.dll"  Alias "GetOutputReportLength"(ByVal pHandle As Integer) As Integer
	Declare Sub hidSetReadNotify Lib "mcHID.dll"  Alias "SetReadNotify"(ByVal pHandle As Integer, ByVal pValue As Boolean)
	Declare Function hidIsReadNotifyEnabled Lib "mcHID.dll"  Alias "IsReadNotifyEnabled"(ByVal pHandle As Integer) As Boolean
	Declare Function hidIsAvailable Lib "mcHID.dll"  Alias "IsAvailable"(ByVal pVendorID As Integer, ByVal pProductID As Integer) As Boolean
	
	' windows API declarations - used to set up messaging...
	Private Declare Function CallWindowProc Lib "user32"  Alias "CallWindowProcA"(ByVal lpPrevWndFunc As Integer, ByVal hwnd As Integer, ByVal Msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
	Private Declare Function SetWindowLong Lib "user32"  Alias "SetWindowLongA"(ByVal hwnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
	
	' windows API Constants
	Private Const WM_APP As Integer = 32768
	Private Const GWL_WNDPROC As Short = -4
	
	' HID message constants
	Private Const WM_HID_EVENT As Decimal = WM_APP + 200
	Private Const NOTIFY_PLUGGED As Short = 1
	Private Const NOTIFY_UNPLUGGED As Short = 2
	Private Const NOTIFY_CHANGED As Short = 3
	Private Const NOTIFY_READ As Short = 4
	
	' local variables
	Private FPrevWinProc As Integer ' Handle to previous window procedure
	Private FWinHandle As Integer ' Handle to message window
	
	' Set up a windows hook to receive notification
	' messages from the HID controller DLL - then connect
	' to the controller
	Public Function ConnectToHID(ByVal pHostWin As Integer) As Boolean
		FWinHandle = pHostWin
		ConnectToHID = hidConnect(FWinHandle)
		'UPGRADE_WARNING: Add a delegate for AddressOf WinProc Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="E9E157F7-EF0C-4016-87B7-7D7FBBC6EE08"'
		FPrevWinProc = SetWindowLong(FWinHandle, GWL_WNDPROC, [color=#FF6600]AddressOf WinProc[/color])
	End Function
	
	' Unhook from the HID controller and disconnect...
	Public Function DisconnectFromHID() As Boolean
		DisconnectFromHID = hidDisconnect
		SetWindowLong(FWinHandle, GWL_WNDPROC, FPrevWinProc)
	End Function
	
	' This is the procedure that intercepts the HID controller messages...
	Private Function WinProc(ByVal pHWnd As Integer, ByVal pMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
		If pMsg = WM_HID_EVENT Then
			Select Case wParam
				
				' HID device has been plugged message...
				Case Is = NOTIFY_PLUGGED
					MainForm.OnPlugged((lParam))
					
					' HID device has been unplugged
				Case Is = NOTIFY_UNPLUGGED
					MainForm.OnUnplugged((lParam))
					
					' controller has changed...
				Case Is = NOTIFY_CHANGED
					MainForm.onchanged()
					
					' read event...
				Case Is = NOTIFY_READ
					MainForm.OnRead((lParam))
			End Select
			
		End If
		
		' next...
		WinProc = CallWindowProc(FPrevWinProc, pHWnd, pMsg, wParam, lParam)
		
	End Function
End Module



Is This A Good Question/Topic? 0
  • +

Replies To: Error from Conversion from VB6 to VB express

#2 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Error from Conversion from VB6 to VB express

Posted 31 December 2009 - 06:59 AM

You'll have to re-write this one by hand I think. It's wrapping a large number of API calls and the translator is not doing a good job translating them. Even if you fix the errors it still won't work. For example it's using VB6.FixedLengthString to marshal Strings which is incorrect but wouldn't show up as an error. Maybe someone has already written a wrapper for the dll file used - mcHID.dll

Looking at the mchid.h file, I see that it uses UINT for handles. That means if you do get this working, you will have to set your .Net application to target x86 as the dll is 32 bit.

This post has been edited by crepitus: 31 December 2009 - 07:27 AM

Was This Post Helpful? 0
  • +
  • -

#3 crepitus  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 84
  • View blog
  • Posts: 383
  • Joined: 08-September 09

Re: Error from Conversion from VB6 to VB express

Posted 31 December 2009 - 07:45 AM

Looks like someone has got something similar to work here:
http://www.picbasic....read.php?t=7748

The code is a mess, but I can't clean it up without the board to test with. There's a bunch of Decimals (16 bytes), Bytes (1 Byte), Shorts (2 bytes) and Longs (8 bytes) when the header file simply uses UINT (4 bytes) and LPVOIDs (4 bytes on x86).

You'll need to set your build target to x86 if you (or anyone who is going to run the program) has a 64 bit OS..

First you may need to do:

Tools->Options->Projects and Solutions->Show advanced build options

Then you can set the Build target:

Build->configuration manager->Select Release or Debug build, then under the platform select New, and use x86.
Was This Post Helpful? 0
  • +
  • -

#4 cxyuan85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-February 09

Re: Error from Conversion from VB6 to VB express

Posted 31 December 2009 - 10:00 PM

thanks for the help.. I have solved the second error but the 1st error still persist.
Error: The value of 'Char' cannot be converted to a double.
To my understanding, my Char is an integer and index is also a integer. i'm trying to convert [chr(BufferIn(Index))] as a double. Is this the right way to convert?

 
Dim BufferIn(BufferInSize) As Byte

Public Sub OnRead(ByVal pHandle As Integer)
		Dim index As Byte
		
		If hidRead(pHandle, BufferIn(0)) Then ' valid ReportID?
			If BufferIn(7) = 0 And BufferIn(8) = 0 Then
			Else
				For index = 1 To BufferInSize ' pass the whole array but skip (0)
					If CDbl(Chr(BufferIn(index))) <> 0 Then ' valid data?
						'tUSBRx.Text = tUSBRx.Text & Chr(BufferIn(index)) ' Yes, send it to the TextBox
					End If
				Next 
			End If
		End If
	End Sub


This post has been edited by cxyuan85: 01 January 2010 - 05:17 PM

Was This Post Helpful? 0
  • +
  • -

#5 cxyuan85  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 12-February 09

Re: Error from Conversion from VB6 to VB express

Posted 01 January 2010 - 05:25 PM

The second error is solved by using CDbl(BufferIn(index)).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1