Timer question

Hello,

I’ve been making some changes in one of my projects that have multiple timers, I use timer1.mode = 0 for off, timer1.mode = 1 to simgle and timer1.mode = 2 for multiple, when I look in the examples did not see the use of 0, 1 and 2 being used but modeoff or modesingle, I ask, do the numbers not being used?

Using class constants in this manner makes your code more readable.

Wayne Golding, Yes I understand that but using 0, 1 and 2 were not deprecated right ?

Nope. It’s just for readability.

  tmpTimer.Mode = Timer.ModeMultiple

instead of

  tmpTimer.Mode = 2

Better readability in your source code, as wisely Wayne answered :slight_smile:

I recommend you to follow the Jedi path… :wink:

I can tell you from my own projects of 15 years, and dealing with Other Peoples Code™ that both styles are ‘correct’, but using the wordy constant is more readable at a glance. Remember, you’re writing your code not only for now and six weeks from now but six years from now.

If you have to go look up what a number means in the documentation you’ve already lost. Timers are easy, since we use them all the time and there are only 3 choices, but there are other parts of the framework that are used less often that have more choices. Go for the readability.

As a side point, I despise the default control names. In your example, the timer1 name tells me nothing about its function. tmrOpenDelay, or tmrOneShot tells me something. I strongly suggest getting into the habit of naming your controls and making the names consistent. Again, the school of hard knocks tells me that this is a better approach than using the default control names. I’ve had to work on Other Peoples Code™ projects with a window full to TextFields with names from TextField1 up to TextField50 and literally had to go in and look at the code to figure out their function. Name them something meaningful and give your future self a break.

@Bob Keeney Excellent post! May I add just to include always a comment at the very first line of the method/event/computed property to explain what this method/etc… actually does and what do you expect. With these in mind, beautiful code and takes less than 21days ( habit time ) to follow Yoda.

Nice Post! :slight_smile:

I would change this to say make method names meaningful and use comments to make things explicitly clear. We usually have Load, Save, Validate methods. No need to put a comment telling someone what they do because the method name is abundantly clear. If I happen to have more than one load-type method I’ll usually break it down into something like Load_ListBox, Load_PopupMenu to make it more obvious. Same thing with Save and Validate.

Comments for the sake of comments irritate me. I fired a developer, once, that put a comment on every simple line of code but then failed to add any comments on a piece of complex code. Comments should be timely and useful - not there for the sake of looking pretty.

BTW, search my blog at http://www.bkeeneybriefs.com. I’ve talked about this topic, and many others, over the last 8 years.

And that’s not to say you’re wrong. If that works for you that’s cool.

Bob, I understand your point of view but I did not say that my timer is called timer1, timer2, etc … I just made a placement of calls from 0, 1 and 2, because I do not think this to be a problem because like you even spoke are only three numbers, regarding timer, listbox, buttons agree that the names have to make sense but this was not my question.

I thank for your attention !

Agreed. I especially loath comments that do nothing more than mirror the code they supposedly comment.

n = 1   // set n to 1

Comments should illuminate, not reiterate.

Sorry. I hijacked your thread. :frowning:

[quote=215719:@Paulo Vargas]Bob, I understand your point of view but I did not say that my timer is called timer1, timer2, etc … I just made a placement of calls from 0, 1 and 2, because I do not think this to be a problem because like you even spoke are only three numbers, regarding timer, listbox, buttons agree that the names have to make sense but this was not my question.

I thank for your attention ![/quote]
While 0 1 and 2 will work I would, as part of regular updating of code, use the named constants

Timer.Mode = 2 doesn’t say much

Timer.Mode = Timer.ModeMultiple does

[quote=215851:@Norman Palardy]While 0 1 and 2 will work I would, as part of regular updating of code, use the named constants

Timer.Mode = 2 doesn’t say much

Timer.Mode = Timer.ModeMultiple does[/quote]

Yes Norman, I will make these changes when doing maintenance in the codes.

I asked because I did not know if 0, 1 and 2 were deprecated and to be honest so far do not know the answer, kkk

Thank you all !

[quote=216017:@Paulo Vargas]Yes Norman, I will make these changes when doing maintenance in the codes.

I asked because I did not know if 0, 1 and 2 were deprecated and to be honest so far do not know the answer, kkk

Thank you all ![/quote]

The numerical value is not deprecated, since you can still get it like

myvalue = Time.ModeMultiple

But the fact that it does not appear anywhere in the LR for Timer should encourage you not to use that.

Moreover if you put the mouse cursor over Time.ModeMultipe in your code you will see at the bottom line Timer.ModeMultiple = 2