locked
sorting text in textbox then to multiple textboxes RRS feed

  • Question

  • Hello,

    Still kind of a newbie here,,

    I have 1 multiline textbox that receives data via a comport

    the data is received almost continuously

    There are 10 outlying stations that are sending data wirelessly to the comport, my program then puts the data (text) into a textbox.

    Each station starts its data with "Station 1" or "Station 2" etc. to "Station 10"

    I need to separate out each stations data and display it in separate textboxes.

    I have searched the forums and  tried everything I can think of with little or no luck.,,,,

    Any ideas or examples would be greatly appreciated!

    Thanks


    Randy

    Thursday, September 12, 2013 5:45 PM

Answers

  • First, in this line:

    sb.Append("Data") 'load data from stream

    You need to replace "Data" with the data you receive, which appears to be [Text].
    sb.Append([Text])

    and should replace this line:

    Me.Txtholding.Text &= [text]   <--- Change this to Me.Txtholding.AppendText([Text]) if you keep it

    unless you want to also maintain the data received in one textbox then add the sb.. line after the Me.Textholding line.

    Next, if you receive data from only one station and all the data for that message in the Receive Text rountine, you need to a revise the code I posted to add the received data to the appropriate textbox.  The code I posted waits until another Station is encountered before sending to the appropriate textbox.  The posted code works like this:

    The stringbuilder contains after first receive:

    Station 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Station 4 xxxxxxx 

    The integer ix will be say 40. so the bolded text is moved to the appropriate text box and removed from the stringbuilder.

    On the next receive of data the string builder looks like this:

    Station 4 xxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyy Station 1 kkkkkkkkkkkkk

    the bolded text was added during the receive, and the station 4 will be sent to station 4 textbox and removed from string builder resulting in this stringbuilder before the next receive:

    Station 1 kkkkkkkkkkkkk

    You do need to revise this line from my code to start the indexof search after position 1:

    Dim ix As Integer = sb.ToString.IndexOf("Station ")

    to

    Dim ix As Integer = sb.ToString.IndexOf("Station ", 2)

    It appears from your code that Station 4 can also be Station4, or Sta 4. Is that correct" If so, you will need to revise the code to deterime the integer ix.

    Also, you can use each station's textbox's TextChanged event to save the data. And remove the other code.  Be sure to save the removed code, I would hate for you to loose it if this doesn't work.

    Post an example of the data received in two ReceiveText executions, and hopefully we can make the code better.


    The difference between genius and stupidity is that genius has its limits.


    Friday, September 13, 2013 2:02 AM

All replies

  • One idea:

    Instead of placing the data in a textbox, place the data in a stringbuilder:

     Dim sb As New System.Text.StringBuilder
            sb.Append("Data") 'load data from stream
    
            'based on timer execute this code
    
            Dim ix As Integer = sb.ToString.IndexOf("Station ")
            If ix > 0 Then
                'new station data
                Dim wrkstation As String = sb.ToString(0, 10)
                Select Case wrkstation
                    Case "Station 1 "
                        txtStation1.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 2 "
                        txtStation2.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                End Select
            End If
    When data from the a different station arrives, it will be append to a textbox and removed from the string builder

    The difference between genius and stupidity is that genius has its limits.


    • Edited by Spooky201 Thursday, September 12, 2013 7:02 PM
    Thursday, September 12, 2013 7:01 PM
  • I tried pasting your code into what I have written in several places that,, well made since to me but couldn't get it to work. I am posting my code so you can see what I am working with,

    
    'Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports
    
    Public Class FmMain
        Dim myPort As Array  'COM Ports detected on the system are stored here
        Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data
    
        Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'When form loads, auto detect all serial ports in the system and populate the cmbPort Combo box.
    
            myPort = IO.Ports.SerialPort.GetPortNames() 'Get all com ports available
    
            CmbBaud.Items.Add(1200)
            CmbBaud.Items.Add(2400)
            CmbBaud.Items.Add(4800)
            CmbBaud.Items.Add(9600)     'Populate the cmbBaud Combo box to common baud rates used
            CmbBaud.Items.Add(19200)
            CmbBaud.Items.Add(38400)
            CmbBaud.Items.Add(57600)
            CmbBaud.Items.Add(115200)
    
            For i = 0 To UBound(myPort)
                CmbPort.Items.Add(myPort(i))
            Next
            CmbPort.Text = CmbPort.Items.Item(0)    'Set cmbPort text to the first COM port detected
            CmbBaud.Text = CmbBaud.Items.Item(0)    'Set cmbBaud text to the first Baud rate on the list
    
            BtnDisconnect.Enabled = False           'Initially Disconnect Button is Disabled
            BtnSend.Enabled = False                     'disconnects "Send" button until connection is made with com port
            BtnSave.Enabled = False                     'disconnects save button until "send" button has been used to populate rtbrevieve
            TxtTransmit.Enabled = False
            BtnClear.Enabled = False
    
            BtnNew.Enabled = False
    
        End Sub
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click
            SerialPort1.PortName = CmbPort.Text         'Set SerialPort1 to the selected COM port at startup
            SerialPort1.BaudRate = CmbBaud.Text         'Set Baud rate to the selected value on
    
            'Other Serial Port Property
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8            'Open our serial port
            SerialPort1.Open()
    
            BtnConnect.Enabled = False          'Disable Connect button
            BtnDisconnect.Enabled = True        'and Enable Disconnect button
            BtnSend.Enabled = True
            CmbPort.Enabled = False
            CmbBaud.Enabled = False
            TxtTransmit.Enabled = True
    
    
           
    
        End Sub
    
        Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisconnect.Click
            SerialPort1.Close()             'Close our Serial Port
    
            BtnConnect.Enabled = True
            BtnDisconnect.Enabled = False
            CmbPort.Enabled = True
            CmbBaud.Enabled = True
            'btnSave.Enabled = False
            BtnSend.Enabled = False
    
            TxtTransmit.Enabled = False
    
        End Sub
    
        Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
            SerialPort1.Write(TxtTransmit.Text & (vbCrLf))
            ' btnSave.Enabled = True
            TxtTransmit.Clear()
            'btnClear.Enabled = True
        End Sub
    
        Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            ReceivedText(SerialPort1.ReadExisting())    'Automatically called every time a data is received at the serialPort
        End Sub
        Private Sub ReceivedText(ByVal [text] As String)
    
            'compares the ID of the creating Thread to the ID of the calling Thread
            If Me.txtReceive1.InvokeRequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.Invoke(x, New Object() {(text)})
            Else
                Me.Txtholding.Text &= [text]
    
                System.Threading.Thread.Sleep(2000)
            End If
    
    
    
            Dim sb As New System.Text.StringBuilder
            sb.Append("Data") 'load data from stream
    
            'based on timer execute this code
    
            Dim ix As Integer = sb.ToString.IndexOf("Station ")
            If ix > 0 Then
                'new station data
                Dim wrkstation As String = sb.ToString(0, 10)
                Select wrkstation
                    Case "Station 1 "
                        txtReceive1.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 2 "
                        TxtReceive2.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
    
                    Case "Station 3 "
                        TxtReceive3.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
    
    end select
            End If
    
    
    
    
    
    
    
    
    
    
    
    
        End Sub
    
    
        Private Sub Txtholding_TextChanged(sender As System.Object, e As System.EventArgs) Handles Txtholding.TextChanged
    
    
    
            If Txtholding.Text.Contains("Station 1") Then
                txtReceive1.AppendText(Txtholding.Text)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station1") Then
                txtReceive1.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 1") Then
                txtReceive1.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 2") Then
                TxtReceive2.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station2") Then
                TxtReceive2.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 2") Then
                TxtReceive2.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 3") Then
                TxtReceive3.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station3") Then
                TxtReceive3.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 3") Then
                TxtReceive3.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 4") Then
                TxtReceive4.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station4") Then
                TxtReceive4.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 4") Then
                TxtReceive4.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 5") Then
                txtReceive5.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station5") Then
                txtReceive5.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 5") Then
                txtReceive5.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 6") Then
                TxtReceive6.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station6") Then
                TxtReceive6.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 6") Then
                TxtReceive6.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
    
            ElseIf Txtholding.Text.Contains("Station 7") Then
                TxtReceive7.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station7") Then
                TxtReceive7.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 7") Then
                TxtReceive7.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 8") Then
                TxtReceive8.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station8") Then
                TxtReceive8.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 8") Then
                TxtReceive8.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Station 9") Then
                TxtReceive9.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Station9") Then
                TxtReceive9.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Sta 9") Then
                TxtReceive9.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
    
    
    
            ElseIf Txtholding.Text.Contains("Statin 10") Then
                TxtReceive10.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Statin10") Then
                TxtReceive10.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            ElseIf Txtholding.Text.Contains("Stat 10") Then
                TxtReceive10.AppendText(Txtholding.Text + vbCrLf)
                Txtholding.Clear()
            End If
            
    
    
        End Sub
    
    
        Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbPort.SelectedIndexChanged
            If SerialPort1.IsOpen = False Then
                SerialPort1.PortName = CmbPort.Text         'pop a message box to user if he is changing ports
            Else                                                                               'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
    
        Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbBaud.SelectedIndexChanged
            If SerialPort1.IsOpen = False Then
                SerialPort1.BaudRate = CmbBaud.Text         'pop a message box to user if he is changing baud rate
            Else                                                                                'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
    
    
    
    
        Private Sub BtnNew_Click(sender As System.Object, e As System.EventArgs) Handles BtnNew.Click
            Dim result = MessageBox.Show("Would You Like To Save The File Before You Open A New Monitor?", "RCsofts Flight Station Control Monitor", MessageBoxButtons.YesNoCancel)
            If result = DialogResult.No Then    'MessageBox.Show("No pressed")
                txtReceive1.Clear()
                'BtnSave.Enabled = False
            ElseIf result = DialogResult.Yes Then   ' MessageBox.Show("Yes pressed")
                Dim SaveFile1 As New SaveFileDialog
    
            End If
    
    
            With SaveFile1
                .AddExtension = True
                .CheckPathExists = True
                SaveFile1.DefaultExt = "*.TXT"
                SaveFile1.Filter = "txt files (*.txt)|*.txt"
                '.InitialDirectory = Desktop\Flight Station Mointor Files
                .OverwritePrompt = True
                .Title = "Select A Drive And Folder To Save This File To"
            End With
    
            If txtReceive1.Text.Contains("Station 1") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station1 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive1.Text, True)
    
            End If
    
    
            If TxtReceive2.Text.Contains("Station 2") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station2 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive2.Text, True)
            End If
    
    
            If TxtReceive3.Text.Contains("Station 3") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station3 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive3.Text, True)
    
            End If
    
            If TxtReceive4.Text.Contains("Station 4") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station4 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive4.Text, True)
            End If
    
    
            If txtReceive5.Text.Contains("Station 5") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station5 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive5.Text, True)
    
            End If
    
    
            If TxtReceive6.Text.Contains("Station 6") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station6 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive6.Text, True)
            End If
    
    
            If TxtReceive7.Text.Contains("Station 7") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station7 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive7.Text, True)
            End If
    
    
            If TxtReceive8.Text.Contains("Station 8") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station8 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive8.Text, True)
            End If
    
    
            If TxtReceive9.Text.Contains("Station 9") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station9 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive9.Text, True)
            End If
    
    
            If TxtReceive10.Text.Contains("Statin 10") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station10 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive10.Text, True)
            End If
    
    
            txtReceive1.Clear()
            TxtReceive2.Clear()
            TxtReceive3.Clear()
            TxtReceive4.Clear()
            txtReceive5.Clear()
            TxtReceive6.Clear()
            TxtReceive7.Clear()
            TxtReceive8.Clear()
            TxtReceive9.Clear()
            TxtReceive10.Clear()
            BtnSave.Enabled = False
            BtnNew.Enabled = False
            BtnClear.Enabled = False
    
    
        End Sub
    
    
        Private Sub BtnClear_Click_1(sender As System.Object, e As System.EventArgs) Handles BtnClear.Click
    
    
            Dim result = MessageBox.Show("Would You Like To Save The File Before You Remove All Text From The Monitor?", "RCsofts Flight Station Control Monitor", MessageBoxButtons.YesNoCancel)
            If result = DialogResult.No Then    'MessageBox.Show("No pressed")
                txtReceive1.Clear()
                TxtReceive2.Clear()
                TxtReceive3.Clear()
                TxtReceive4.Clear()
                txtReceive5.Clear()
                TxtReceive6.Clear()
                TxtReceive7.Clear()
                TxtReceive8.Clear()
                TxtReceive9.Clear()
                TxtReceive10.Clear()
                BtnSave.Enabled = False
                BtnNew.Enabled = False
                BtnClear.Enabled = False
            End If
    
            If result = DialogResult.Yes Then   ' MessageBox.Show("Yes pressed")
    
                Dim SaveFile1 As New SaveFileDialog
                
            End If
    
    
            With SaveFile1
                .AddExtension = True
                .CheckPathExists = True
                SaveFile1.DefaultExt = "*.TXT"
                SaveFile1.Filter = "txt files (*.txt)|*.txt"
                '.InitialDirectory = Desktop\Flight Station Mointor Files
                .OverwritePrompt = True
                .Title = "Select A Drive And Folder To Save This File To"
            End With
    
            If txtReceive1.Text.Contains("Station 1") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station1 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive1.Text, True)
    
            End If
    
    
            If TxtReceive2.Text.Contains("Station 2") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station2 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive2.Text, True)
            End If
    
    
            If TxtReceive3.Text.Contains("Station 3") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station3 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive3.Text, True)
    
            End If
    
            If TxtReceive4.Text.Contains("Station 4") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station4 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive4.Text, True)
            End If
    
    
            If txtReceive5.Text.Contains("Station 5") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station5 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive5.Text, True)
    
            End If
    
    
            If TxtReceive6.Text.Contains("Station 6") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station6 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive6.Text, True)
            End If
    
    
            If TxtReceive7.Text.Contains("Station 7") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station7 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive7.Text, True)
            End If
    
    
            If TxtReceive8.Text.Contains("Station 8") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station8 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive8.Text, True)
            End If
    
    
            If TxtReceive9.Text.Contains("Station 9") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station9 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive9.Text, True)
            End If
    
    
            If TxtReceive10.Text.Contains("Statin 10") Then
                With SaveFile1
                    .AddExtension = True
                    .CheckPathExists = True
                    SaveFile1.DefaultExt = "*.TXT"
                    SaveFile1.Filter = "txt files (*.txt)|*.txt"
                    '.InitialDirectory = Desktop\Flight Station Mointor Files
                    .OverwritePrompt = True
                    .Title = "Select A Drive And Folder To Save This File To"
                End With
                SaveFile1.FileName = "Triple Tree Flight Station10 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive10.Text, True)
            End If
    
    
            txtReceive1.Clear()
            TxtReceive2.Clear()
            TxtReceive3.Clear()
            TxtReceive4.Clear()
            txtReceive5.Clear()
            TxtReceive6.Clear()
            TxtReceive7.Clear()
            TxtReceive8.Clear()
            TxtReceive9.Clear()
            TxtReceive10.Clear()
            BtnSave.Enabled = False
            BtnNew.Enabled = False
            BtnClear.Enabled = False
    
    
    
    
    
    
    
    
    
    
    
        End Sub
    
    
    
        Private Sub BtnSave_Click(sender As System.Object, e As System.EventArgs) Handles BtnSave.Click
            Dim SaveFile1 As New SaveFileDialog
            With SaveFile1
                .AddExtension = True
                .CheckPathExists = True
                SaveFile1.DefaultExt = "*.TXT"
                SaveFile1.Filter = "txt files (*.txt)|*.txt"
                '.InitialDirectory = Desktop\Flight Station Mointor Files
                .OverwritePrompt = True
                .Title = "Select A Drive And Folder To Save This File To"
            End With
    
    
    
            If txtReceive1.Text.Contains("Station 1") Then
                SaveFile1.FileName = "Triple Tree Flight Station1 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive1.Text, True)
            End If
    
    
            If TxtReceive2.Text.Contains("Station 2") Then
                SaveFile1.FileName = "Triple Tree Flight Station2 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive2.Text, True)
            End If
    
    
            If TxtReceive3.Text.Contains("Station 3") Then
                SaveFile1.FileName = "Triple Tree Flight Station3 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive3.Text, True)
            End If
    
    
            If TxtReceive4.Text.Contains("Station 4") Then
                SaveFile1.FileName = "Triple Tree Flight Station4 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive4.Text, True)
            End If
    
    
            If txtReceive5.Text.Contains("Station 5") Then
                SaveFile1.FileName = "Triple Tree Flight Station5 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, txtReceive5.Text, True)
            End If
    
    
    
            If TxtReceive6.Text.Contains("Station 6") Then
                SaveFile1.FileName = "Triple Tree Flight Station6 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive6.Text, True)
            End If
    
    
            If TxtReceive7.Text.Contains("Station 7") Then
                SaveFile1.FileName = "Triple Tree Flight Station7 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive7.Text, True)
            End If
    
    
            If TxtReceive8.Text.Contains("Station 8") Then
                SaveFile1.FileName = "Triple Tree Flight Station8 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive8.Text, True)
            End If
    
    
            If TxtReceive9.Text.Contains("Station 9") Then
                SaveFile1.FileName = "Triple Tree Flight Station9 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive9.Text, True)
            End If
    
    
            If TxtReceive10.Text.Contains("Statin 10") Then
                SaveFile1.FileName = "Triple Tree Flight Station10 " + DateTime.Now.ToString("dddd--MM-dd-yyyy,-hh-mm-ss-tt")
                SaveFile1.ShowDialog()
                My.Computer.FileSystem.WriteAllText(SaveFile1.FileName, TxtReceive10.Text, True)
            End If
    
    
    
            BtnSave.Enabled = False
    
        End Sub
    
        Private Sub txtReceive1_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtReceive1.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            txtReceive1.SelectionStart = txtReceive1.TextLength
            txtReceive1.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive2_TextChanged(sender As System.Object, e As System.EventArgs)
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive2.SelectionStart = TxtReceive2.TextLength
            TxtReceive2.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive3_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive3.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive3.SelectionStart = TxtReceive3.TextLength
            TxtReceive3.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive4_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive4.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive4.SelectionStart = TxtReceive4.TextLength
            TxtReceive4.ScrollToCaret()
        End Sub
    
        Private Sub txtReceive5_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtReceive5.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            txtReceive5.SelectionStart = txtReceive5.TextLength
            txtReceive5.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive6_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive6.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive6.SelectionStart = TxtReceive6.TextLength
            TxtReceive6.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive7_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive7.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive7.SelectionStart = TxtReceive7.TextLength
            TxtReceive7.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive8_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive8.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive8.SelectionStart = TxtReceive8.TextLength
            TxtReceive8.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive9_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive9.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive9.SelectionStart = TxtReceive9.TextLength
            TxtReceive9.ScrollToCaret()
        End Sub
    
        Private Sub TxtReceive10_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtReceive10.TextChanged
            BtnSave.Enabled = True
            BtnClear.Enabled = True
            BtnNew.Enabled = True
            TxtReceive10.SelectionStart = TxtReceive10.TextLength
            TxtReceive10.ScrollToCaret()
        End Sub
        Private Sub fmMain_Formclosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
    
            SerialPort1.Close()             'Close our Serial Port
            Application.Exit()
        End Sub
    
        
    End Class
    
    
    
    
    
    

    I know a lot of it would need to be removed after inserting your code, I just cant seem to figure out where it should be.

    Thanks


    Randy

    Friday, September 13, 2013 12:13 AM
  • First, in this line:

    sb.Append("Data") 'load data from stream

    You need to replace "Data" with the data you receive, which appears to be [Text].
    sb.Append([Text])

    and should replace this line:

    Me.Txtholding.Text &= [text]   <--- Change this to Me.Txtholding.AppendText([Text]) if you keep it

    unless you want to also maintain the data received in one textbox then add the sb.. line after the Me.Textholding line.

    Next, if you receive data from only one station and all the data for that message in the Receive Text rountine, you need to a revise the code I posted to add the received data to the appropriate textbox.  The code I posted waits until another Station is encountered before sending to the appropriate textbox.  The posted code works like this:

    The stringbuilder contains after first receive:

    Station 3 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Station 4 xxxxxxx 

    The integer ix will be say 40. so the bolded text is moved to the appropriate text box and removed from the stringbuilder.

    On the next receive of data the string builder looks like this:

    Station 4 xxxxxxxyyyyyyyyyyyyyyyyyyyyyyyyy Station 1 kkkkkkkkkkkkk

    the bolded text was added during the receive, and the station 4 will be sent to station 4 textbox and removed from string builder resulting in this stringbuilder before the next receive:

    Station 1 kkkkkkkkkkkkk

    You do need to revise this line from my code to start the indexof search after position 1:

    Dim ix As Integer = sb.ToString.IndexOf("Station ")

    to

    Dim ix As Integer = sb.ToString.IndexOf("Station ", 2)

    It appears from your code that Station 4 can also be Station4, or Sta 4. Is that correct" If so, you will need to revise the code to deterime the integer ix.

    Also, you can use each station's textbox's TextChanged event to save the data. And remove the other code.  Be sure to save the removed code, I would hate for you to loose it if this doesn't work.

    Post an example of the data received in two ReceiveText executions, and hopefully we can make the code better.


    The difference between genius and stupidity is that genius has its limits.


    Friday, September 13, 2013 2:02 AM
  • Topdog,

    I will work on this as soon as I can,, may be a day or two before I get back to you.

    putting in a new server here at work and I am trying to get everything switched over, and a lot of stuff dumped. Like where someone has put multiple instances of folders named Shared Documents on the same drive! 


    Randy

    Friday, September 13, 2013 11:12 AM
  • OK,, found some time to try this out

    I removed the code that I think didn't deal with the receiving parts as I figured we/I could deal with that later.

    Below is the code..

    but I cant get it to work..

    Imports System
    Imports System.ComponentModel
    Imports System.Threading
    Imports System.IO.Ports
    
    Public Class FmMain
        Dim myPort As Array  'COM Ports detected on the system are stored here
        Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing of data
    
        Private Sub form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            'When form loads, auto detect all serial ports in the system and populate the cmbPort Combo box.
    
            myPort = IO.Ports.SerialPort.GetPortNames() 'Get all com ports available
    
            CmbBaud.Items.Add(1200)
            CmbBaud.Items.Add(2400)
            CmbBaud.Items.Add(4800)
            CmbBaud.Items.Add(9600)     'Populate the cmbBaud Combo box to common baud rates used
            CmbBaud.Items.Add(19200)
            CmbBaud.Items.Add(38400)
            CmbBaud.Items.Add(57600)
            CmbBaud.Items.Add(115200)
    
            For i = 0 To UBound(myPort)
                CmbPort.Items.Add(myPort(i))
            Next
            CmbPort.Text = CmbPort.Items.Item(0)    'Set cmbPort text to the first COM port detected
            CmbBaud.Text = CmbBaud.Items.Item(0)    'Set cmbBaud text to the first Baud rate on the list
    
            BtnDisconnect.Enabled = False           'Initially Disconnect Button is Disabled
            BtnSend.Enabled = False                     'disconnects "Send" button until connection is made with com port
            BtnSave.Enabled = False                     'disconnects save button until "send" button has been used to populate rtbrevieve
            TxtTransmit.Enabled = False
            BtnClear.Enabled = False
    
            BtnNew.Enabled = False
    
        End Sub
    
        Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnConnect.Click
            SerialPort1.PortName = CmbPort.Text         'Set SerialPort1 to the selected COM port at startup
            SerialPort1.BaudRate = CmbBaud.Text         'Set Baud rate to the selected value on
    
            'Other Serial Port Property
            SerialPort1.Parity = IO.Ports.Parity.None
            SerialPort1.StopBits = IO.Ports.StopBits.One
            SerialPort1.DataBits = 8            'Open our serial port
            SerialPort1.Open()
    
            BtnConnect.Enabled = False          'Disable Connect button
            BtnDisconnect.Enabled = True        'and Enable Disconnect button
            BtnSend.Enabled = True
            CmbPort.Enabled = False
            CmbBaud.Enabled = False
            TxtTransmit.Enabled = True
    
    
    
    
        End Sub
    
        Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDisconnect.Click
            SerialPort1.Close()             'Close our Serial Port
    
            BtnConnect.Enabled = True
            BtnDisconnect.Enabled = False
            CmbPort.Enabled = True
            CmbBaud.Enabled = True
            'btnSave.Enabled = False
            BtnSend.Enabled = False
    
            TxtTransmit.Enabled = False
    
        End Sub
    
        Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
            SerialPort1.Write(TxtTransmit.Text & (vbCrLf))
            ' btnSave.Enabled = True
            TxtTransmit.Clear()
            'btnClear.Enabled = True
        End Sub
    
        Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
            ReceivedText(SerialPort1.ReadExisting())    'Automatically called every time a data is received at the serialPort
        End Sub
        Private Sub ReceivedText(ByVal [text] As String)
    
            'compares the ID of the creating Thread to the ID of the calling Thread
            If Me.txtReceive1.InvokeRequired Then
                Dim x As New SetTextCallback(AddressOf ReceivedText)
                Me.Invoke(x, New Object() {(text)})
            Else
                Me.Txtholding.AppendText([text])
    
                System.Threading.Thread.Sleep(2000)
            End If
    
    
            Dim sb As New System.Text.StringBuilder
            sb.Append([text]) 'load data from stream
    
            'based on timer execute this code
    
            Dim ix As Integer = sb.ToString.IndexOf("Station ", 2)
            If ix > 0 Then
                'new station data
                Dim wrkstation As String = sb.ToString(0, 10)
                Select Case wrkstation
                    Case "Station 1 "
                        txtReceive1.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 2 "
                        TxtReceive2.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 3 "
                        TxtReceive3.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 4 "
                        TxtReceive4.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 5 "
                        txtReceive5.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 6 "
                        TxtReceive6.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 7 "
                        TxtReceive7.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 8 "
                        TxtReceive8.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 9 "
                        TxtReceive9.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                    Case "Station 10 "
                        TxtReceive10.AppendText(sb.ToString.Substring(0, ix - 1))
                        sb.Remove(0, ix - 1)
                End Select
            End If
    
        End Sub
    
        Private Sub cmbPort_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbPort.SelectedIndexChanged
            If SerialPort1.IsOpen = False Then
                SerialPort1.PortName = CmbPort.Text         'pop a message box to user if he is changing ports
            Else                                                                               'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
    
        Private Sub cmbBaud_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmbBaud.SelectedIndexChanged
            If SerialPort1.IsOpen = False Then
                SerialPort1.BaudRate = CmbBaud.Text         'pop a message box to user if he is changing baud rate
            Else                                                                                'without disconnecting first.
                MsgBox("Valid only if port is Closed", vbCritical)
            End If
        End Sub
    
    End Class

    Also,, just to clarify as the original code was pretty botched up.

    There are 10 stations sending text over wireless to a wireless comport

    The data\text from each station always begins with Station 1 or Station 2,, etc.

    I am monitoring temp and lighting at 10 different locations on site

    the idea is to keep record of power usage throughout our facility.

    its 17 acres with 8 buildings.

    So, on the code,, what did I do wrong?

    Randy


    Randy

    Friday, September 13, 2013 3:03 PM
  • Try moving this line:

    Dim sb As New System.Text.StringBuilder

    to be a class level variable.  Outside any method.   For example:

    Public Class FmMain Dim myPort As Array 'COM Ports detected on the system are stored here Delegate Sub SetTextCallback(ByVal [text] As String) 'Added to prevent threading errors during receiveing

    Dim sb As New System.Text.StringBuilder

    Currently, a new instance of sb is created each time ReceivedText is executed.

    Do you received data from multiple stations in one receive?


    The difference between genius and stupidity is that genius has its limits.



    • Edited by Spooky201 Friday, September 13, 2013 4:02 PM
    Friday, September 13, 2013 3:59 PM
  • tried it,, got this error:

    Cross-thread operation not valid: Control 'txtReceive1' accessed from a thread other than the thread it was created on.

    error occurred at:

    txtReceive1.AppendText(sb.ToString.Substring(0, ix - 1)

    Do  you receive data from multiple stations in one receive"  No

    each station transmits independently so each receive is also independent.

    although, it is possible that one transmit/receive could occur during another transmit/receive

    the output stations are set to transmit every few minutes. they are not sinked together

    the transmit is triggered by a timer in the circuit that monitors the building.

     right now, for testing purposes,  I am transmitting manually from three modules so I can send independently or simultaneously. as I didn't want to install the building monitoring modules until I had a working.

    I realize this whole process would be easier by using an internet connection, but the buildings are not interconnected,, thus my plan to use the radio, xbees  


    Randy

    Friday, September 13, 2013 4:53 PM
  • 'compares the ID of the creating Thread to the ID of the calling Thread If Me.txtReceive1.InvokeRequired Then Dim x As New SetTextCallback(AddressOf ReceivedText) Me.Invoke(x, New Object() {(text)}) Else Me.Txtholding.AppendText([text])  Dim wrkstation As String = [Text].ToString(0, 10)
                Select Case wrkstation
                    Case "Station 1 "
                        txtReceive1.AppendText([Text] & vbCrLf)
                    Case "Station 2 "
                        txtReceive2.AppendText([Text] & vbCrLf)

    End Select

    System.Threading.Thread.Sleep(2000)   

    End If

    Since you receive data from only one station in a receive, the code can be simplified. The stringbuilder was used in case a partial message for a station was received or multiple station messages were received. The code assumes the message starts with "Station XX" in the first 10 characters.

    Edit: I will be away from the computer for a few days, so if you encounter more problems, start a new post.


    The difference between genius and stupidity is that genius has its limits.


    • Edited by Spooky201 Friday, September 13, 2013 5:23 PM
    Friday, September 13, 2013 5:21 PM
  •    Pasted in the above code where it indicated.

    Got this error:

    Overload resolution failed because no accessible 'ToString' accepts this number of arguments.

    error occurred at:

    Dim wrkstation As String = [text].ToString(0, 10)


    Randy

    Friday, September 13, 2013 5:35 PM
  • s/b Dim wrkstation As String = [text].ToString.Substring(0, 10)

    or

    Dim wrkstation As String = [text].Substring(0, 10) since [Text] is a string


    The difference between genius and stupidity is that genius has its limits.


    • Edited by Spooky201 Friday, September 13, 2013 7:07 PM
    Friday, September 13, 2013 7:05 PM