Results 1 to 7 of 7

Thread: Changing text in label with timer

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Changing text in label with timer

    Hi all,

    I am new here and I have one problem. I have to implement code that will change text in label every second with timer. Text values are: "maximum" and "minimum", so text in label should change from "maximum" to "minimum" and vice versa every second (ok, timer interval = 1000).
    I will appreciate if anyone can help me.
    Thanks in advance

  2. #2
    Member
    Join Date
    Jun 2012
    Posts
    58

    Re: Changing text in label with timer

    Off the top of my head...
    Use the timer.tick event.

    In the timer1.tick event:
    Code:
    if label1.text = "max" then
    label1.text = "min"
    and vice versa.

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Re: Changing text in label with timer

    Thank you very much for quick response, I'll try this one...

  4. #4
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Changing text in label with timer

    Try this with the timer interval set to 1000

    Code:
        Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
            Static minmax As Boolean = False
            minmax = Not minmax
            If minmax Then
                Label1.Text = "maximum"
            Else
                Label1.Text = "minimum"
            End If
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  5. #5

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Re: Changing text in label with timer

    Thanks dbasnett,
    I am new to VB, so please if you have time to explain to me line of code: minmax = Not minmax, which I don't understand at all.
    Thank you in advance

  6. #6
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Changing text in label with timer

    Not performs logical negation on the boolean(a true false data type). A boolean can have two values. Not changes the value to the opposite. Link for Not

    If you put a Stop before the statement and then step through the code you will see this.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  7. #7

    Thread Starter
    New Member
    Join Date
    Apr 2013
    Posts
    6

    Re: Changing text in label with timer

    Ok,I understand it.
    Thank you very much once again. Cheers!

Tags for this Thread

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