Instruction MOD
Hi,
Sometime in your code, you have to use a function who increase one value and when this value arrive in maximum, you have to return to 0.
We could code like this:
Public Sub Button1_Click()
Select Case mycounter
Case 0
TextBox1.Text = "text for one clic"
Inc mycounter
Case 1
TextBox1.Text = "text for two clic"
Inc mycounter
Case 2
TextBox1.Text = "text for three clic"
Inc mycounter
Case 3
TextBox1.Text = "text for four clic"
Inc mycounter
Case 4
TextBox1.Text = "text for five clic"
Inc mycounter
Case 5
TextBox1.Text = "text to return to the beggining"
mycounter = 0
End Select
LCDLabel1.Value = mycounter
End
This code work correctly, but a lot of repeated code.
We can use MOD function and code again like this:
Public Sub Button2_Click()
Select Case mycounter
Case 0
TextBox2.Text = "text for one clic"
Case 1
TextBox2.Text = "text for two clic"
Case 2
TextBox2.Text = "text for three clic"
Case 3
TextBox2.Text = "text for four clic"
Case 4
TextBox2.Text = "text for five clic"
Case 5
TextBox2.Text = "text to return to the beggining"
End Select
mycounter = (mycounter + 1) Mod 6
LCDLabel2.Value = mycounter
End
very good tips in this line:
mycounter = (mycounter + 1) Mod 6
6 is the number of choice you want :
here from 0 to 5 (6 choice) puis return to 0.
Thanks for your attention.