+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 10 of 12

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

  1. #1
    Logan's Avatar
    Logan is offline Programming Professional
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Posts
    226
    Rep Power
    13

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

    Ok, I don't have any screen shots ATM, so bear with my code-only tut.
    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...
    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.

    Code:
    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...

    Code:
    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
    Last edited by Logan; 08-09-2009 at 08:09 PM.
    http://forum.codecall.net/image.php?type=sigpic&userid=17757&dateline=123284  0697

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,448
    Blog Entries
    74
    Rep Power
    143

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

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

  4. #3
    Logan's Avatar
    Logan is offline Programming Professional
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Posts
    226
    Rep Power
    13

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

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

    Code:
    thisoddnumber = thisoddnumber + 1
    If thisoddnumber > 5 then
    mitymer.enabled = False
    it should be

    Code:
    thisoddnumber = thisoddnumber + 1
    Print thisoddnumber
    If thisoddnumber = 5 then
    mitymer.enabled = False
    http://forum.codecall.net/image.php?type=sigpic&userid=17757&dateline=123284  0697

  5. #4
    Jordan Guest

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

    Nice little tutorial, +rep!

  6. #5
    Join Date
    Sep 2008
    Location
    Kosovo
    Posts
    4,032
    Rep Power
    44

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

    nice one .. +rep

  7. #6
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

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

    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:

    Code:
    thisoddnumber = thisoddnumber + 1
    This should be written like this:

    Code:
    thisoddnumber += 1
    Also, you have this:

    Code:
    If thisoddnumber = 5 then
    mitymer.enabled = False
    This code is inefficient and and If conditional statement is unnecessary. Consider this:

    Code:
    mitymer.Enabled = Not (thisoddnumber = 5)

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

  8. #7
    Join Date
    Nov 2008
    Location
    Kosovo.
    Posts
    2,391
    Rep Power
    30

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

    Nice One .. +rep .

  9. #8
    Logan's Avatar
    Logan is offline Programming Professional
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Posts
    226
    Rep Power
    13

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

    No Xav, I like my inefficient code. It's pretty, and nice for the n00bs.
    http://forum.codecall.net/image.php?type=sigpic&userid=17757&dateline=123284  0697

  10. #9
    Join Date
    Aug 2007
    Location
    Gizeh, Al Jizah, Egypt, Egypt
    Posts
    8,675
    Blog Entries
    12
    Rep Power
    81

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

    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"
    Code:
    eval(base64_decode("cHJpbnQgJ2kgbG92ZSBvbmUtbGluZSBjb2Rlcyc7"));
    www.amrosama.com | the unholy methods of javascript

  11. #10
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,174
    Blog Entries
    13
    Rep Power
    114

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

    @Logan: it isn't pretty at all. It is terrible code.

    Newcomers to programming should be taught good programming technique IMO.

    Quote Originally Posted by Jordan View Post
    Good members, like yourself, stick around and post for ages to come!
    Mr. Xav | Blog | Forums

+ Reply to Thread
Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. fscanf for a certain amount of lines
    By th72468 in forum C and C++
    Replies: 5
    Last Post: 09-23-2011, 07:24 AM
  2. How many Times?
    By TeenChristian in forum The Lounge
    Replies: 13
    Last Post: 07-01-2010, 06:32 AM
  3. Measuring Amount of Web Traffic
    By uberlax in forum C# Programming
    Replies: 3
    Last Post: 08-31-2009, 12:11 AM
  4. Amount of Time Programming Vs. Debugging
    By Roybob in forum General Programming
    Replies: 3
    Last Post: 01-08-2009, 01:42 PM
  5. Replace any amount of space
    By Frantic in forum C# Programming
    Replies: 4
    Last Post: 08-16-2006, 07:23 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts