Resolved Reading Data from Textboxes

ravoll

Well-known member
Joined
Aug 26, 2010
Messages
50
Programming Experience
Beginner
Hi All ,
I'm still at it.Have a new delima

I have a form with 5 textboxes.1 thru 4 are read only ,and display various data recieved during my process.
#5 is a user input,and accepts only numbers.

View attachment Top Speed.bmp

Basicly if I enter 33 into textbox5,then "recieving" should stop when textbox 4 displays 33 KmH,but it don't for some reason.If I type it manually,(like I have with the frequency in the textbox1 event) it works.
Right now I stop my program when the Fx 's match but nee it to function over the KmH.
VB.NET:
Public Class Form1


    Dim RPM As Double
    Dim KmH As Double
    Dim Recieving As Boolean = False
    Dim cycles As Double  'cycles are impulses/6
    Dim impulse As Integer = 1
    Dim imp_count As Integer = 0
    Dim updatetext As Integer

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        If SerialPort1.IsOpen = False Then
            SerialPort1.Open() 'open the port for access'  
            Button1.Text = "Stop"
            Button2.Enabled = True
        Else
            SerialPort1.Close()
            Button1.Text = "Start"
        End If
    End Sub
    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        If impulse > 0 Then
        End If
        If Recieving = True Then
            imp_count = imp_count + 1

            updatetext = imp_count
        End If
        Me.Invoke(New EventHandler(AddressOf TextUpdate))


    End Sub
    Private Sub TextUpdate(ByVal sender As Object, ByVal e As EventArgs)
        TextBox1.Text = updatetext
        TextBox2.Text = updatetext
        TextBox3.Text = updatetext
        TextBox4.Text = updatetext

    End Sub
    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        TextBox1.Text = imp_count
        If TextBox1.Text < 350 Then
            Recieving = True
        Else
            Recieving = False
        End If
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
        cycles = (imp_count / 6)
        TextBox2.Text = cycles


    End Sub
    Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
        RPM = (cycles * 60)
        TextBox3.Text = RPM
    End Sub


    Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
        KmH = 5.1 * 3.141592654 * RPM / 100 * 0.06
        TextBox4.Text = KmH              'Displays speed

    End Sub


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Clear()
        TextBox2.Clear()
        TextBox3.Clear()
        TextBox4.Clear()
    End Sub

    Private Sub TextBox5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox5.TextChanged
        If Not IsNumeric(TextBox5.Text) Or TextBox5.Text = "" Then
            TextBox5.Text = "" 'prevents input other the number' 
            Button1.Enabled = False ' No input, disable button...' 
        Else
            Button1.Enabled = True ' Valid input, enable button...' 
        End If
    End Sub
End Class

Oh yeah and another thing.How can I manually clear the textboxes 1 thru 4 afterwards.The code I'm trying doesn't work,where as It has worked on other form's.
 
Based on your code provided in post #13 it looks like you're setting the textboxes text:
VB.NET:
    Private Sub TextUpdate(ByVal sender As Object, ByVal e As EventArgs)
        TextBox1.Text = updatetext
        TextBox2.Text = updatetext
        TextBox3.Text = updatetext
        TextBox4.Text = updatetext
    End Sub
Which for each one will fire the TextChanged event, which is where you check your reset boolean and what you want is, which should be working fine so it could be that when the whole process is supposed to stop, the serial port keeps running. I don't see you stopping the serial port (I see where you start it) anywhere in the code.

Also you might want to turn Option Strict On in the project's properties, it'll help you fix a whole slew of potential errors with your code.
 
Based on your code provided in post #13 it looks like you're setting the textboxes text:
VB.NET:
    Private Sub TextUpdate(ByVal sender As Object, ByVal e As EventArgs)
        TextBox1.Text = updatetext
        TextBox2.Text = updatetext
        TextBox3.Text = updatetext
        TextBox4.Text = updatetext
    End Sub
Which for each one will fire the TextChanged event, which is where you check your reset boolean and what you want is, which should be working fine so it could be that when the whole process is supposed to stop, the serial port keeps running. I don't see you stopping the serial port (I see where you start it) anywhere in the code.

Also you might want to turn Option Strict On in the project's properties, it'll help you fix a whole slew of potential errors with your code.

I don't close the serialport when the process stops.I only stop reading from the port.When the process stops then I press the "Stop" button,"Reset" the count and "Start" again.Pressing "Start" and "Stop" opens and closes my port.
 
Back
Top