Should I use a LOOKUP, a REGEX or what? How would you do it?

piscis

Well-known member
Joined
Jun 30, 2003
Messages
54
Gentlemen:

Could you let me know what strategy would you use for doing the following?

The Example Data shown below is being gathered from a Machine through the RS232 port into a RichTextBox1 in VB.NET

Once the Data is in the RichTextBox1 we need to parse it into Textboxes, which are labeled accordingly for the User to examine the collected data.

Once the Data is examined, the user clicks the SAVE button and the data is inserted into the Datagrid1 below on the same mainform1, thereby creating a new record entry in the Database.

Here is the explanation of The Example Data below; lets take line 8 as an example;

CA3*450*325*225*0*775*650*350*425

Each Asterisk separates a field name; there are 8 fields in this line.

Value 450 is field CA301
Value 325 is field CA302
Value 225 is field CA303
Value 0 is field CA304
 
not sure if this helps :
Code:
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim str() As String = "CA3*450*325*225*0*775*650*350*425".Split("*")
        Dim fakeTextBox() As String = DirectCast(str, Array)
        Dim i As Integer, x As Integer, tb As Control
        For i = 1 To 8
            x = i - 1
            For Each tb In Me.Controls
                If TypeOf tb Is TextBox Then
                    If tb.Name = "TextBox" & i Then
                        tb.Text = fakeTextBox(x)
                    End If
                End If
            Next
        Next
    End Sub
 
Back
Top