a simple boxe timer (code included)


Closed Thread
Results 1 to 25 of 25

Hybrid View

  1. #1
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    Jeremy will correct it for you. If he does his IQ is 120+
    Already did...down to 38 lines. But since nobody else can read it, decided not to post it...and didn't use select case. Those numbers aren't linear, but they're close enough to do some math on to get the desired results...thereby resulting in a simple single if/then/endif 3-line statement to handle all those if/then's.

  2. #2
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    Can you post a readable example using either IF's or Select Case?

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    Can you post a readable example using either IF's or Select Case?
    Nope...
    It's a state secret now, top notch double-A rating, return postage included...
    And it's doesn't have IF's, it has a single IF statement

  4. #4
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    That's a shame Jeremy, I was going to expose you to the world as border line genius.
    Last edited by T.Jackson; - 19th June 2008 at 17:37.

  5. #5
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    I realize that I'm a bit drunk at the moment, now I'm saying 105+

  6. #6
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    The usual suspects.

  7. #7
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    I realize that I'm a bit drunk at the moment, now I'm saying 105+
    Then step away from the keyboard and go chase parked cars or something...

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Talking

    Quote Originally Posted by T.Jackson View Post
    That's a shame Jeremy, I was going to expose you to the world as border line genius.
    I've already exposed myself. I don't need any help.

  9. #9
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    One possible "improved" solution is as follows ...

    Code:
       Select Case b1
          Case Is < 219                                        
             timerN = 3
             timerAc = 120
             timerBc = 60     
          
          Case Is < 243                                         
             timerN = 2
             timerAc = 180
             timerBc = 60
    
          Case Is <= 255                                         
             timerN = 1
             timerAc = 600
             timerBc = 180 
       End Select
    That code will do exactly the same job as ...

    Code:
        If (b1 <= 255 And b1 >= 243) Then
            timerN = 1
            timerAc = 600
            timerBc = 180
        End If
        If (b1 <= 242 And b1 >= 219) Then
            timerN = 2
            timerAc = 180
            timerBc = 60
        End If
        If (b1 <= 218 And b1 >= 193) Then
            timerN = 3
            timerAc = 120
            timerBc = 60
        End If
    BUT, it'll probably compile to half the size, run twice as fast, be more readable, easier to comprehend and definitely far easier to maintain.

    Regards,

    Trent Jackson
    Last edited by T.Jackson; - 20th June 2008 at 17:44.

  10. #10
    T.Jackson's Avatar
    T.Jackson Guest


    Did you find this post helpful? Yes | No

    Default

    I might add also that the same thing is possible using IF's, select case is always more effcient though however.

    Code:
          for (int i = 0; i < 12; i++)
          {
              sample = tempArray[i];
              
              if (sample < 0)
                 rangeA++;
              else if (sample < 10)
                 rangeB++;
              else if (sample < 20)
                 rangeC++;
              else if (sample < 30)
                 rangeD++;
              else
                 rangeE++;
          }
    Notice how we start with the smallest number first? Always start with the smallest value first and work downwards with the next biggest value.

    Hope it helps

    Trent Jackson

  11. #11
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    What
    is
    so
    hard
    to
    read
    with
    colons
    ?

    I
    think
    they
    help
    make
    the
    code
    MORE
    readable
    if
    used
    in
    the
    right
    place.

    It
    makes
    it
    more
    like
    reading
    a
    book.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Replies: 5
    Last Post: - 24th February 2009, 18:55
  3. Making Program Code Space your playground...
    By Melanie in forum Code Examples
    Replies: 15
    Last Post: - 19th July 2008, 08:26
  4. Interrupt/timer not really interrupting...
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd May 2005, 22:05
  5. Timer Accuracy
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 31st March 2005, 05:26

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

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