hi guys wondering if you can help i have thrown together a rough and ready project using winsock, now it is just thrown together to see if i could get it to work the problem is (well it does work first of all) when i receive data it is in the ascii format :dispframe: 0000: 0000: : 0000 i dont need the dispframe but i would like to have the remainder in seperate text boxs by the way the project is for a set of scales which when connected sends display data to pc

Dani AI

Generated

Quick note: posted the sample string ":dispframe: 0000: 0000: : 0000" and correctly pointed out a simple split approach. That works for straightforward, complete messages, but real serial/socket streams often include leading/trailing separators, empty tokens, or arrive in partial chunks. A more robust pattern is to accumulate incoming bytes into a small buffer, then extract only the meaningful fields (numbers) while leaving any incomplete tail in the buffer for the next arrival.

Example (VB6, Winsock control): collect data in the DataArrival event, use VBScript.RegExp to find number tokens, assign the first N matches to the text boxes, and then remove the processed portion from the buffer so partial frames are preserved.

Private buffer As String

Private Sub Winsock1_DataArrival(ByVal BytesTotal As Long)
    Dim chunk As String
    Winsock1.GetData chunk, vbString
    buffer = buffer & chunk

    ' Requires reference to "Microsoft VBScript Regular Expressions 5.5"
    Dim re As RegExp
    Set re = New RegExp
    re.Pattern = "(\d+)"
    re.Global = True

    Dim mc As MatchCollection
    Set mc = re.Execute(buffer)

    If mc.Count >= 3 Then
        TextBox1.Text = mc.Item(0).Value
        TextBox2.Text = mc.Item(1).Value
        TextBox3.Text = mc.Item(2).Value

        ' remove processed data up to last matched number
        Dim last As String
        last = mc.Item(mc.Count - 1).Value
        buffer = Mid$(buffer, InStrRev(buffer, last) + Len(last))
    End If
End Sub

Notes and troubleshooting:

  • If the scale sends CR/LF or a known terminator, detect that instead of guessing by numbers.
  • Adjust the regex to accept decimals or signs (e.g., ([+-]?\d+(\.\d+)?)) if needed.
  • Ensure GetData uses the correct encoding; in VB.NET use Encoding.ASCII.GetString and marshal UI updates onto the UI thread.
  • Keep the buffer logic simple: never discard data until you are sure a frame was fully parsed.

use the split function using : as your find character.

Then, using your array set your textboxes = to the proper indices.

textbox.text = myarray(1) etc.

myarray(0) will hold the text "dispframe" and you should probably drop the leading :

Make sense?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.