Jump to content

VB .NET How to make a timer only go (#) amount of times

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
11 replies to this topic

#1
Logan

Logan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 226 posts
Ok, I don't have any screen shots ATM, so bear with my code-only tut. :P
This tutorial is for those of you with a little Visual Basic experience but are still beginners.



First off say you wanted to make your form print out a number 5 times, 1, 2, 3, 4, and 5. You think "HEY, MICROSOFT IS COOL THEY PROBABLY MADE SOMETHING WITH THE TIMER TO SET THE AMOUNT OF TIME'S IT GOES OFF!!! YEA AREN'T I SMART!!" Well, no. Sorry, but they didn't. Here's how you would do it though.


First you make a form with a single button on it, and a timer. For the button make the code...
mitymer.enabled = True
Ok now that you have that when you hit the button the timer starts. Now above the button code you need to put the declarations, or declaration in this case.

Dim thisoddnumber As Integer = 0

Now that you have the declaration, you can start the timer coding. Double click on the timer so you get to the code view and add this...

thisoddnumber = thisoddnumber + 1
If thisoddnumber = 5 then
mitymer.enabled = False

You can make the numbers anything, it doesn't really matter but you also have to change all of them accordingly. I should have the screen shots up later tonight or tomorrow. Thanks for reading, and alert me of any bugs :P

Edited by Logan, 09 August 2009 - 07:09 PM.


#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Nice. Isn't amazing how often a "feature" isn't really needed?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
Logan

Logan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 226 posts
I can't edit it so I guess I'll post it down here... For the timer code, instead of

thisoddnumber = thisoddnumber + 1
If thisoddnumber > 5 then
mitymer.enabled = False

it should be

thisoddnumber = thisoddnumber + 1
Print thisoddnumber
If thisoddnumber = 5 then
mitymer.enabled = False


#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Nice little tutorial, +rep! :)

#5
Egz0N

Egz0N

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,034 posts
nice one .. +rep :)

#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I have never got the Print funtion to work in .NET. I believe it is a feature of VB6 only.

Also, I look at this code:

thisoddnumber = thisoddnumber + 1

This should be written like this:

thisoddnumber += 1

Also, you have this:

If thisoddnumber = 5 then
mitymer.enabled = False

This code is inefficient and and If conditional statement is unnecessary. Consider this:

mitymer.Enabled = Not (thisoddnumber = 5)

Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
mendim.

mendim.

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,393 posts
Nice One .. +rep .

#8
Logan

Logan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 226 posts
No Xav, I like my inefficient code. It's pretty, and nice for the n00bs.

#9
amrosama

amrosama

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 8,675 posts
very nice tiutorial
+rep when i can
yo homie i heard you like one-line codes so i put a one line code that evals a decrypted one line code that prints "i love one line codes"
eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
www.amrosama.com | the unholy methods of javascript

#10
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
@Logan: it isn't pretty at all. It is terrible code.

Newcomers to programming should be taught good programming technique IMO.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#11
Logan

Logan

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 226 posts
Well so should your mom but you don't see me complaining. :)

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
My mother does not learn programming, thus your statement is invalid. You fail lulz.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums