Question

I'm not sure how to word this question, but essentially I have a label that by default reads "0"

I want it so that I can change the value up and down depending on certain factors. I don't want to use something like Label1.Text = "1" because I might have two functions updating the label. I might require one function to add a 1 and, but I might also need a function to take away 1.

I've been looking through data types and think I might need to look at declaring the label text as an Integer?

Could someone please give me a practical example, or at least point me in the correct direction?

Apologies if this question is elementary but I'd rather get some solid advice, along with explained best practice here then Copy + paste code I don't understand.

Was it helpful?

Solution

Why don't you just set the value of the label to a variable, and update that variable from wherever you need?

For instance:

Private _myIndex As Integer = 0

Sub Increment()
    _myIndex += 1
    UpdateLabel()
End Sub

Sub Decrement()
    _myIndex -= 1
    UpdateLabel()
End Sub

Sub UpdateLabel()
    Label1.Text = CStr(_myIndex)
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top