Results 1 to 3 of 3

Thread: Serial data string to multiple textboxes

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Unhappy Serial data string to multiple textboxes

    I have tried to read from the serial port and display the string content to 4 textboxes. Problem is when I use Mid, then only the first Textbox displays data, there is nothing on the others. If I jump over the first one then only the second one shows data.


    [Private Sub btnVoltage_Click()
    Timer1.Enabled = True
    MSComm1.Output = ("B9" & vbCr)
    txtDataReceived1.Text = Mid(MSComm1.Input, 5, 4)
    txtDataReceived2.Text = Mid(MSComm1.Input, 9, 4)
    txtDataReceived3.Text = Mid(MSComm1.Input, 13, 4)
    txtDataReceived4.Text = Mid(MSComm1.Input, 21, 4)


    End Sub]

    Thanks

  2. #2
    Hyperactive Member gtilles's Avatar
    Join Date
    Dec 2004
    Location
    Planet Earth
    Posts
    394

    Re: Serial data string to multiple textboxes

    Your first read is clearing the buffer, subsequent reads will be empty.
    Put the contents in a string variable first.
    Then use the string to fill the textboxes
    Try

    dim myInput as string
    Timer1.Enabled = True
    MSComm1.Output = ("B9" & vbCr)
    'You should allow at least 50ms delay here, (Sleep Function)
    'between write and reads
    myInput=MSComm1.Input
    txtDataReceived1.Text = Mid(myInput, 5, 4)
    txtDataReceived2.Text = Mid(myInput, 9, 4)
    txtDataReceived3.Text = Mid(myInput, 13, 4)
    txtDataReceived4.Text = Mid(myInput, 21, 4)
    Last edited by gtilles; Sep 13th, 2007 at 12:35 PM.
    Truly, you have a dizzying intellect.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2007
    Location
    Sweden
    Posts
    359

    Smile Re: Serial data string to multiple textboxes

    Hi
    Thanks for your support, I must say that I'm not so good with VB. Probably should I read more books;-
    I'll try the code @ work tomorrow.

    Thank's

Posting Permissions

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



Click Here to Expand Forum to Full Width