-1

Is there some kind of update feature like in C# for Visual Studio 2012 in vb.net? (so that it will continuously check to see if an if statement is fulfilled)

MilkToast
  • 201
  • 1
  • 3
  • 11
  • 1
    Could you elaborate what you're talking about? Are you talking about the Watch window? – sloth Jun 10 '14 at 10:31
  • I don't know what that is but say I have a label and every time you click the label it adds one to itself. Say I wanted there to be a message saying "1000" once the label gets to 1000. I know I would need something like " If Label1 = ("1000") then Msgbox("1000")" but where would I insert this code to make it continuously check the status of the label. – MilkToast Jun 10 '14 at 10:38
  • 1
    Well, you talked about a *update feature like in C#*. So my question is what C# feature are you talking about? Also, if you create an event handler that alters the text of a label, you can put your check into that very event handler itself. – sloth Jun 10 '14 at 10:44
  • I mean the update function that runs the code every frame – MilkToast Jun 10 '14 at 11:16

2 Answers2

0

Try something like this:

Dim iClicks As Integer = 0

Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    iClicks += 1
    Label1.Text = iClicks.ToString()

    If iClicks = 1000 Then
        MessageBox.Show("1000 reached!")
    End If
End Sub

It's better to have a integer counter than checking the string value and performing conversion each time. As you can see, the code checks the click counter each time you click the label.


If you want to check the value periodically, add a Timer and perform the check in its event:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If iClicks = 1000 Then
        MessageBox.Show("1000 reached!")
    End If
End Sub

But consider the need to do this, because maybe it's not necessary and will decrease the performance comparing it with the other way.

SysDragon
  • 9,692
  • 15
  • 60
  • 89
0

There is probably a better way of doing this, but what I've done when I need a constant "update" function, is just use a Timer, then handle the Ticks.

Easiest way of implementing it is to go to the form designer, in the Toolbox, under Components, drag a timer onto the form. Double-click it to add a handle for its Tick event.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    If WhateverYoureLookingFor = True
        'Do stuff
    End If
End Sub

This is obviously VB, but easy to convert to C#.

Keith
  • 1,331
  • 2
  • 13
  • 18