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

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

  1. #1
    Programming Professional Logan will become famous soon enough Logan's Avatar
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Age
    14
    Posts
    224

    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 10:09 PM.
    http://forum.codecall.net/image.php?type=sigpic&userid=17757&dateline=123284  0697

  2. #2
    Super Moderator WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther has much to be proud of WingedPanther's Avatar
    Join Date
    Jul 2006
    Age
    36
    Posts
    11,665
    Blog Entries
    57

    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?
    CodeCall Blog | CodeCall Wiki | Shareware
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  3. #3
    Programming Professional Logan will become famous soon enough Logan's Avatar
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Age
    14
    Posts
    224

    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

  4. #4
    Administrator Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan is a name known to all Jordan's Avatar
    Join Date
    Nov 2005
    Location
    Hendersonville, NC
    Posts
    24,556
    Blog Entries
    97

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

    Nice little tutorial, +rep!

  5. #5
    Code Warrior Egz0N is a name known to all Egz0N is a name known to all Egz0N is a name known to all Egz0N is a name known to all Egz0N is a name known to all Egz0N is a name known to all Egz0N's Avatar
    Join Date
    Sep 2008
    Location
    Kosovo
    Age
    18
    Posts
    4,030

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

    nice one .. +rep

  6. #6
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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

  7. #7
    Guru mendim. is a jewel in the rough mendim. is a jewel in the rough mendim. is a jewel in the rough mendim. is a jewel in the rough mendim.'s Avatar
    Join Date
    Nov 2008
    Location
    Kosovo.
    Posts
    2,393

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

    Nice One .. +rep .

  8. #8
    Programming Professional Logan will become famous soon enough Logan's Avatar
    Join Date
    Oct 2008
    Location
    Ohio, Us
    Age
    14
    Posts
    224

    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

  9. #9
    Code Warrior
    /////////|||||\\\\\\\\\
    amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama is a splendid one to behold amrosama's Avatar
    Join Date
    Aug 2007
    Location
    Pyramids st, Giza, Egypt
    Age
    21
    Posts
    8,182
    Blog Entries
    12

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

    very nice tiutorial
    +rep when i can

  10. #10
    Xav
    Xav is offline
    Code Slinger Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav has much to be proud of Xav's Avatar
    Join Date
    Mar 2008
    Location
    The North Pole
    Posts
    13,210
    Blog Entries
    13

    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
1 2 LastLast

Thread Information

Users Browsing this Thread

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

     

Similar Threads

  1. Replies: 18
    Last Post: 07-08-2009, 03:55 PM
  2. VB 6.0: Tutorial, How to Make Glass2K!!
    By TcM in forum VB Tutorials
    Replies: 17
    Last Post: 05-01-2009, 06:31 AM
  3. make a label box in vb : help
    By iTTaleem in forum Visual Basic Programming
    Replies: 3
    Last Post: 01-20-2008, 04:06 AM
  4. Managed C++ calling VB .net dll function
    By pranab73 in forum Managed C++
    Replies: 0
    Last Post: 12-25-2007, 12:19 PM
  5. How to make Dumplings
    By ahsan16 in forum The Lounge
    Replies: 2
    Last Post: 01-11-2007, 10:55 PM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

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