Results 1 to 11 of 11

Thread: [RESOLVED] reset a temp alarm

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Resolved [RESOLVED] reset a temp alarm

    hello
    I'm building a temp monitor application to monitor 16 temperatures. The application is running fine.
    I want to improve it a little bit by adding blinking colour and maybe an alarm sound if a temp is above limit. I use a button to reset the alarm blinking but cant make it to stop.
    I use 2 timers, one for reading the value and one for the blinking data.

    Code:
    Public Class Form1
        Dim a As Integer = 1
        Dim s As Integer = 1
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            a = TextBox2.Text
            '' alarm point is 10
            If a > 10 Then
                Timer2.Enabled = True
            Else
                Timer2.Enabled = False
                    Label1.BackColor = Color.White
                    s = 1
                End If
                Label1.Visible = True
                Label1.Text = TextBox2.Text
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object,
        ByVal e As System.EventArgs) Handles Button1.Click
    
            Timer2.Enabled = False
            s = 0
    
        End Sub
        Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
            Label1.BackColor = Color.Red
            Label1.Text = a
            Label1.Visible = Not Label1.Visible
        End Sub
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            ''i insert the values in the textbox2
            TextBox2.Text = 1
        End Sub
    End Class
    i can make it blink but i cant stop it blinking while the temp is above normal.

    Thanks

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    Code:
    '' alarm point is 10
    If a > 10 Then
         ' make a 10 or lower here
        Timer2.Enabled = True

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Re: reset a temp alarm

    can you explain a bit what you mean?

    I need to stop blinking when i press the button even if the temp is above alarm point.

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    Quote Originally Posted by koskap View Post
    can you explain a bit what you mean?

    I need to stop blinking when i press the button even if the temp is above alarm point.
    The problem is the timer1 tick will start timer2 if the value in TextBox2 is greater than 10. The way to stop that happening when you click the button to stop the timer2, is to clear TextBox2.

    Also a TextBox' Text property is a String, even if it contains an Integer...

    The correct way to retrieve an Integer from TextBox2...

    Code:
    Dim a as Integer
    If Integer.TryParse(TextBox2.Text, a) Then
        'a  = the Integer contained in TextBox2
    End If

  5. #5

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Re: reset a temp alarm

    Found the answer, i rearranged the IF statements. Now when the temp is above normal, Timer2 will kick in and the blinking begins. When i press the button the blinking stops

    Code:
     Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            a = TextBox2.Text
            '' alarm point is 10
            If a < 10 Then
                Timer2.Enabled = False
                Label1.BackColor = Color.White
                s = 1
            Else
                If s <> 0 Then
                    Timer2.Enabled = True
                 
                End If
            End If
    
            Label1.Visible = True
                Label1.Text = TextBox2.Text
        End Sub

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    Quote Originally Posted by koskap View Post
    Code:
    a = TextBox2.Text
    What happens when the user types 'hello' in TextBox2???

  7. #7

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Re: reset a temp alarm

    Normally it will give an error BUT in the app im building the input is always numbers. The app takes readings from temperature and pressure sensors and displays them on the screen

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    If your controls are just for display and not input, use a display control... That's what Labels are for. No possibility of someone crashing your app...

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    If you want to allow numeric input from your user, use a NumericUpDown control...

  10. #10
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,479

    Re: reset a temp alarm

    In the end, you'll do what you'll do, But a String is not a number, and an Integer is a whole number and not a String. Turn Option Strict on, and VS will force you to fix those errors

  11. #11

    Thread Starter
    New Member
    Join Date
    Feb 2021
    Posts
    7

    Re: [RESOLVED] reset a temp alarm

    Thanks Paul for your suggestions, i will change the textbox into Label for input. This part of coding was only for testing

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