Page loading

Share your opinion
What do you think about gambaslinux.fr?
 
Interesting
It miss some informations
Excellent website
Results
WIDGETS GAMBAS
GAMBAS 3 SOFTWARES
TUTORIALS
Library
_gb3.pngDivers - Instructions

Instruction MOD

 


 

modfunction.jpg



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.


Download exemple source code here.(rename file in tar.gz to extract correctly)

Creation date : 31/12/2015 @ 11:09
Last update : 31/12/2015 @ 11:16
Category : Divers
Page read 3342 times


Print the article Print the article


react.gifReactions to this article

Nobody gave a comment yet.
Be the first one to do it!


QUICK MENU
SEARCH




LANGUAGE
COMPONENTS
Other
LANGUAGE
Where, who?
VISITS

   visitors

   visitors online

ARCHIVES GAMBAS 1/2
^ Top ^