Results 1 to 5 of 5

Thread: [RESOLVED] ListBox items will be added infinitely

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Resolved [RESOLVED] ListBox items will be added infinitely

    Let me make the long story short. A part of my application is a small "Active alarm monitoring" thing which works by comparing plenty of variables by set-points and if they are critical, out of range, etc. it sorts the corresponding parameter. Whole process will operate on a timer control. Therefore, adding an item [as an alarm] keeps repeating.

    I'm looking for a way of programming to do same thing "once". Thanx everyone

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

    Re: ListBox items will be added infinitely

    Can you show us your code?

  3. #3
    PowerPoster Poppa Mintin's Avatar
    Join Date
    Mar 2009
    Location
    Bottesford, North Lincolnshire, England.
    Posts
    2,429

    Re: ListBox items will be added infinitely

    Without your code it's not easy to give an answer, but it sounds as though...
    If you set a Boolean variable whilst you're processing one alarm... And if you don't allow another to process whilst the boolean is set...
    Maybe add any new alarms to a list of 'Do these when it's clear' you could also check that they're not duplicated before you process the next.


    Poppa
    Along with the sunshine there has to be a little rain sometime.

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

    Re: ListBox items will be added infinitely

    Code:
    Public Class Form13
    
        Private WithEvents tmr As New Timer With {.Interval = 1000}
    
        Private Sub Form13_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            tmr.Start()
        End Sub
    
        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            If ListBox1.FindStringExact("the item you're planning to add") = -1 Then ' doesn't contain
                ListBox1.Items.Add("the item you're planning to add")
            End If
        End Sub
    
    End Class

  5. #5

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Re: ListBox items will be added infinitely

    Quote Originally Posted by .paul. View Post
    Code:
    Public Class Form13
    
        Private WithEvents tmr As New Timer With {.Interval = 1000}
    
        Private Sub Form13_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            tmr.Start()
        End Sub
    
        Private Sub tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmr.Tick
            If ListBox1.FindStringExact("the item you're planning to add") = -1 Then ' doesn't contain
                ListBox1.Items.Add("the item you're planning to add")
            End If
        End Sub
    
    End Class
    Hey Paul! I wish you would add more description about your code however comments are clear and helpful. Thanks. I will consider your method but I'm thinking about another way to to do the same for example using Text1.Text TextChanged event which performs longer than timer's interval. .FindStringExact was dope tho ; )))))))

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