[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
Re: ListBox items will be added infinitely
Can you show us your code?
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
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
Re: ListBox items will be added infinitely
Quote:
Originally Posted by
.paul.
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 ; )))))))