VB Help


Closed Thread
Results 1 to 36 of 36

Thread: VB Help

Hybrid View

  1. #1
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Hi Gadelhas, Thanks for your help. Let me assure you first I am completely new to this. Just started learning it yesterday.

    I understand your examples, but I am still confused.

    I have it reading the serial port now. I have a button set up that when I press it, it sends a char to the pic, and the pic responds with 18 bytes. This seems to work good, everytime I press the button.

    What I want to do is set up a timer(I think I can do that based on examples found surfing) to "press the button for me" every 100mS or so.

    So the "form1_load" section is where the start of the program is?

    I really don't understand how the code "flows". All the beginner tutorals seem to be the same thing: add a button, add a textbox. Add code in the button event to put text in the text box.
    None explain how the overall code is executed. Please see that I think in terms of coding a PIC. ie: there is a main loop, inside the loop we check things and gosub or goto different parts of the code, then we get back to the main and return to the beginning. we may even have interrupts that will stop what is happening and run some other code, then return to what it was doing before.

    So to me all the button events are like the sub-routines, that get called when we press the button. but where do they return to?

    If I used the examples you gave, will the "code" just hang out in lala land until a byte is received?

    Am I thinking too hard?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Yup, in VB, everything is "Event driven", so the software Wait 'till the next event, process the event... and then take a break before the next event.

    Should you have any further problem, post your whole project/solution here. I can definitely help on that.

    Check the SerialPort settings, you can trigger the SerialPort Event after having receive a certain amount of incoming bytes.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    I assume this is all of it. If not I don't know where to find it.
    Code:
    PublicClass Form1
    Dim getdata AsByte
     
     
    PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Dim namearray() AsString
    namearray = IO.Ports.SerialPort.GetPortNames
    If namearray(0) = ""Then
    TextBox1.Text = "none found!"
    Else
    'ComboBox1.Text = namearray(0)
    SerialPort1.PortName = namearray(0)
    TextBox1.Text = SerialPort1.PortName
    EndIf
     
    EndSub
    PrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Dim i AsInteger
    Dim datain AsByte
    Dim data(20) AsShort
    If getdata = 0 Then
    SerialPort1.Open()
    getdata = 1
    EndIf
    'Do While getdata <> 0
    SerialPort1.Write("k")
    For i = 0 To 17
    datain = SerialPort1.ReadByte()
    data(i) = datain
    Next
    gxhb.Text = (data(0) * 256) + data(1)
    'gxlb.Text = Hex(data(1))
    gyhb.Text = (data(2) * 256) + data(3)
    'gylb.Text = Hex(data(3))
    gzhb.Text = (data(4) * 256) + data(5)
    'gzlb.Text = Hex(data(5))
    axhb.Text = (data(6) * 256) + data(7)
    'axlb.Text = Hex(data(7))
    ayhb.Text = (data(8) * 256) + data(9)
    'aylb.Text = Hex(data(9))
    azhb.Text = (data(10) * 256) + data(11)
    'azlb.Text = Hex(data(11))
    cxhb.Text = (data(12) * 256) + data(13)
    'cxlb.Text = Hex(data(13))
    cyhb.Text = (data(14) * 256) + data(15)
    'cylb.Text = Hex(data(15))
    czhb.Text = (data(16) * 256) + data(17)
    'czlb.Text = (data(17))
    'Loop
     
     
    EndSub
    PrivateSub Panel2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs)
    EndSub
    PrivateSub czlb_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles czlb.TextChanged
    EndSub
    PrivateSub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
    getdata = 0
    SerialPort1.Close()
    EndSub
    PrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    'Do While 0 < 1
    If getdata = 1 Then
    TextBox1.Text = "sub ran"
    Else
    TextBox1.Text = "sub else ran"
    EndIf
    'Loop
    EndSub
    EndClass

    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  4. #4
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    Having just read walters post, it seems to me I need a timer, that when it fires it runs the code now in the button_2 press. It would run the code everytime the timer condition is met? Then the button code needs a check for if getdata is 1 or 0. so really the code is inside an if_then.

    Then the timer is my event.

    BTW, if the code I posted makes no sense, my appalogies.

    How to setup the timer for every 50 ms?
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

  5. #5
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default How did you post code WITH color??

    Hey Bert (cncmachineguy),

    How did you post code with the color formatting?
    I would like to be able to do that... (I think everyone should) as it makes code much more readable.'
    Is it the type of editor you copied the code from?? I notice that other posts in this thread do not have color formatting.

    thanks
    Last edited by Heckler; - 30th May 2011 at 16:40.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

  6. #6
    Join Date
    Aug 2010
    Location
    Maryland, USA
    Posts
    869


    Did you find this post helpful? Yes | No

    Default Re: VB Help

    This code was copied from VB express IDE. The color came with it. Would have been nice if the spacing had also followed along.

    I have NO idea why, normally I would have had to highlight and change color for all things not black.

    I think the other posts were prolly just typed up on the spot
    -Bert

    The glass is not half full or half empty, Its twice as big as needed for the job!

    http://foamcasualty.com/ - Warbird R/C scratch building with foam!

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts