Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help required with Visual basic (Visual studio 2008)

Status
Not open for further replies.

fuuton

Advanced Member level 4
Joined
Jul 21, 2010
Messages
104
Helped
9
Reputation
18
Reaction score
2
Trophy points
1,298
Location
Pakistan, Rawalpindi
Activity points
1,881
Hi all,

I am using a code for sending data from PC to pic18f4550 through usb and I am encountering an error in the following statement:

Code:
Public Sub hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) [B]As Boolean[/B]

hidWriteEx(VendorID, ProductID, BufferOut(0))

The error is "end of statement expected" at "As Boolean"

Please help me out.

Thanks in advance
 

Code:
End Sub      [B][I]' Write this line at the end of your procedure, indicating the end[/I][/B]

Hope this help
 


The error tells you that you did not end the sub-routine declaration. End sub is used to end it. It's like if...end if. So, you declare public sub....end sub.

Hope this helps.
Tahmid.
 

Have a look at the above links...

Then reply me..
and according to me you have not used hidWriteEx function properly,
In my code i had used it as follow:-

Have a look at this and it is working fine for me,

Code:
Private Sub btn_Send_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Send.Click
        BufferOut(0) = 0
        For Me.i = 1 To Len(txt_Data_to_Send.Text)
            BufferOut(i) = Asc(Mid(txt_Data_to_Send.Text, i))
        Next

        hidWriteEx(VendorID, ProductID, BufferOut(0))
    End Sub

This is to send data,

You have not suggested your problem properly,
Take some time to explain you problem, so that one on this forum can help you properly,

You can also upload your Solution in Zip Folder, so that i can see what is the problem..

---------- Post added at 20:49 ---------- Previous post was at 20:47 ----------

The error tells you that you did not end the sub-routine declaration. End sub is used to end it. It's like if...end if. So, you declare public sub....end sub.

Hey Tahmid i had already told him that, but that doesn't solve his problem.
I think he had done some big mistake.

Can you upload your solution file..
 

Try with this:

Code:
Public Function hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean
 

Hi all,

Thanks for the replies so far. The complete code is as follows:

Code:
Public Class frmUSB
    ' vendor and product IDs
    Private Const VendorID As Integer = &H1234    'Replace with your device's
    Private Const ProductID As Integer = &H1      'product and vendor IDs

    ' read and write buffers
    Private Const BufferInSize As Integer = 1 'Size of the data buffer coming IN to the PC
    Private Const BufferOutSize As Integer = 1    'Size of the data buffer going OUT from the PC
    Dim BufferIn(BufferInSize) As Byte          'Received data will be stored here - the first byte in the array is unused
    Dim BufferOut(BufferOutSize) As Byte    'Transmitted data is stored here - the first item in the array must be 0
    Dim button_output As Byte
    ' ****************************************************************
    ' when the form loads, connect to the HID controller - pass
    ' the form window handle so that you can receive notification
    ' events...
    '*****************************************************************
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' do not remove!
        ConnectToHID(Me)
    End Sub

    '*****************************************************************
    ' disconnect from the HID controller...
    '*****************************************************************
    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        DisconnectFromHID()
    End Sub

    '*****************************************************************
    ' a HID device has been plugged in...
    '*****************************************************************
    Public Sub OnPlugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            ' ** YOUR CODE HERE **
            Button11.BackColor = Color.GreenYellow


        End If
    End Sub

    '*****************************************************************
    ' a HID device has been unplugged...
    '*****************************************************************
    Public Sub OnUnplugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
            ' ** YOUR CODE HERE **
            Button11.BackColor = Color.Red


        End If
    End Sub

    '*****************************************************************
    ' controller changed notification - called
    ' after ALL HID devices are plugged or unplugged
    '*****************************************************************
    Public Sub OnChanged()
        ' get the handle of the device we are interested in, then set
        ' its read notify flag to true - this ensures you get a read
        ' notification message when there is some data to read...
        Dim pHandle As Integer
        pHandle = hidGetHandle(VendorID, ProductID)
        hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
    End Sub

    '*****************************************************************
    ' on read event...
    '*****************************************************************
    Public Sub OnRead(ByVal pHandle As Integer)
        ' read the data (don't forget, pass the whole array)...
        If hidRead(pHandle, BufferIn(0)) Then
            ' ** YOUR CODE HERE **
            ' first byte is the report ID, e.g. BufferIn(0)
            ' the other bytes are the data from the microcontroller...
        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        button_output = &H1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        button_output = &H2
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        button_output = &H3
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        button_output = &H4
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        button_output = &H5
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        button_output = &H6
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        button_output = &H7
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        button_output = &H8
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        button_output = &H9
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        button_output = &HA
    End Sub
End Class

'*****************************************************************
' on read event...
'*****************************************************************
Public Sub hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean 

    hidWriteEx(VendorID, ProductID, BufferOut(0))

End Sub

@Arun Sharma:

I want to build a similar project that is indicated in the links that you specified. If possible, could you send me a link to the application code for the VB part?

Regards
 

Yes i can send That Visual Basic Project, right now i haven't uploaded that code.

Give me your email id, i will mail it to you..

and as far as your code is concerned, your code is wrong
Code:
Public Sub hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean 

    hidWriteEx(VendorID, ProductID, BufferOut(0))

End Sub

Actually i am not an good programmer of visual basic, but according to me it is wrong,
You have to use this function with button click's to send data, and your are using it in a wrong way.
in my code i had directly used the hidWriteEx function, you must also use that in the same way.

and i want to know what u want to do with this,
My personal advice is to put the hidwriteex function inside button as follow:-
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        button_output = &H1
        BufferOut(0) = 0
        BufferOut(1) = button_output
'Or if you want to send acii data try this BufferOut(1) = Asc(button_output)
'then use this
       hidWriteEx(VendorID, ProductID, BufferOut(0))

    End Sub

I am sure this will work and delete the line from your code,
And if problem persist upload your form and its code in Zip Format

---------- Post added at 08:06 ---------- Previous post was at 08:05 ----------

Yes i can send That Visual Basic Project, right now i haven't uploaded that code.

Give me your email id, i will mail it to you..

and as far as your code is concerned, your code is wrong
Code:
Public Sub hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean 

    hidWriteEx(VendorID, ProductID, BufferOut(0))

End Sub

Actually i am not an good programmer of visual basic, but according to me it is wrong,
You have to use this function with button click's to send data, and your are using it in a wrong way.
in my code i had directly used the hidWriteEx function, you must also use that in the same way.

and i want to know what u want to do with this,
My personal advice is to put the hidwriteex function inside button as follow:-
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        button_output = &H1
        BufferOut(0) = 0
        BufferOut(1) = button_output
'Or if you want to send acii data try this BufferOut(1) = Asc(button_output)
'then use this
       hidWriteEx(VendorID, ProductID, BufferOut(0))

    End Sub

I am sure this will work and delete the line from your code,
And if problem persist upload your form and its code in Zip Format
 
  • Like
Reactions: fuuton

    fuuton

    Points: 2
    Helpful Answer Positive Rating
I had mailed you the code...
Have a look at it..

Its better you post your code here, i mean to say solution file..

Have you tried to do what i have said in the previous post, you haven't tell me the results


And Sorry i don't use skype, if you want we can chat on gmail account
 
Last edited:

It seems that you want to use the mentioned function as an on-read action. This is what I can get from the comments in code in post #8 (I've shown this in blue). However, looking at the function, it is only a declaration (in red), and nothing is being done in the function (in brown). However, from within the function, you're calling itself. So, you're not really doing anything. Moreover, since it returns a value as boolean, it should be declared as function and not sub (in green).

Whatever it is you're trying to do as an on-read event/action, it should be written in the onread subroutine (in purple).

You also did not post what this hidWriteEx function is supposed to do, as here it is pretty much a "blank" function that's not doing anything.

Code:
Public Class frmUSB
    ' vendor and product IDs
    Private Const VendorID As Integer = &H1234    'Replace with your device's
    Private Const ProductID As Integer = &H1      'product and vendor IDs

    ' read and write buffers
    Private Const BufferInSize As Integer = 1 'Size of the data buffer coming IN to the PC
    Private Const BufferOutSize As Integer = 1    'Size of the data buffer going OUT from the PC
    Dim BufferIn(BufferInSize) As Byte          'Received data will be stored here - the first byte in the array is unused
    Dim BufferOut(BufferOutSize) As Byte    'Transmitted data is stored here - the first item in the array must be 0
    Dim button_output As Byte
    ' ****************************************************************
    ' when the form loads, connect to the HID controller - pass
    ' the form window handle so that you can receive notification
    ' events...
    '*****************************************************************
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' do not remove!
        ConnectToHID(Me)
    End Sub

    '*****************************************************************
    ' disconnect from the HID controller...
    '*****************************************************************
    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        DisconnectFromHID()
    End Sub

    '*****************************************************************
    ' a HID device has been plugged in...
    '*****************************************************************
    Public Sub OnPlugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            ' ** YOUR CODE HERE **
            Button11.BackColor = Color.GreenYellow


        End If
    End Sub

    '*****************************************************************
    ' a HID device has been unplugged...
    '*****************************************************************
    Public Sub OnUnplugged(ByVal pHandle As Integer)
        If hidGetVendorID(pHandle) = VendorID And hidGetProductID(pHandle) = ProductID Then
            hidSetReadNotify(hidGetHandle(VendorID, ProductID), False)
            ' ** YOUR CODE HERE **
            Button11.BackColor = Color.Red


        End If
    End Sub

    '*****************************************************************
    ' controller changed notification - called
    ' after ALL HID devices are plugged or unplugged
    '*****************************************************************
    Public Sub OnChanged()
        ' get the handle of the device we are interested in, then set
        ' its read notify flag to true - this ensures you get a read
        ' notification message when there is some data to read...
        Dim pHandle As Integer
        pHandle = hidGetHandle(VendorID, ProductID)
        hidSetReadNotify(hidGetHandle(VendorID, ProductID), True)
    End Sub

    '*****************************************************************
    ' on read event...
    '*****************************************************************
[COLOR="#4B0082"]    Public Sub OnRead(ByVal pHandle As Integer)
        ' read the data (don't forget, pass the whole array)...
        If hidRead(pHandle, BufferIn(0)) Then
            ' ** YOUR CODE HERE ** ------------------------------------------------------->>>> Write your code here
            ' first byte is the report ID, e.g. BufferIn(0)
            ' the other bytes are the data from the microcontroller...
        End If
    End Sub[/COLOR]

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        button_output = &H1
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        button_output = &H2
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        button_output = &H3
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        button_output = &H4
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        button_output = &H5
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        button_output = &H6
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        button_output = &H7
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        button_output = &H8
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        button_output = &H9
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        button_output = &HA
    End Sub
End Class
[COLOR="#0000FF"]
'*****************************************************************
' on read event...
'*****************************************************************[/COLOR]
[COLOR="#FF0000"]'Public Sub hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean [/COLOR]
Public [COLOR="#006400"]Function[/COLOR] hidWriteEx(ByVal pVendorID As Integer, ByVal pProductID As Integer, ByRef pData As Byte) As Boolean

   [COLOR="#A52A2A"]hidWriteEx(VendorID, ProductID, BufferOut(0))[/COLOR]
[COLOR="#FF0000"]
'End Sub[/COLOR]
End [COLOR="#006400"]Function[/COLOR]

Hope this helps.
Tahmid.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top