ELSEIF Block Would be Good.


Closed Thread
Results 1 to 31 of 31
  1. #1
    T.Jackson's Avatar
    T.Jackson Guest

    Post ELSEIF Block Would be Good.

    Be great if PBP supported ELSEIF structure - something a bit like the following...

    Code:
       ElseIf GetAsyncKeyState(vbKeyF1) Then               '(F1) Show palette
          If Key_Pressed(vbKeyF1) = 0 Then                 'Key not held down?
             LED_Palette.Show                              'Show palette
             Key_Pressed(vbKeyF1) = 1                      'Set flag
          End If
             
       ElseIf GetAsyncKeyState(vbKeyF6) Then               '(F6) Next frame
          If Key_Pressed(vbKeyF6) = 0 Then                 'Key not held down?
             Adj_Button = 0                                'Set flag
             Call Apply_Frame_Num_Adj                      'Jump to proc
             Key_Pressed(vbKeyF6) = 1                      'Set flag
          End If
    ELSEIF can be quite advantageously in some cases, consider the following complex procedure and how it would need to be done if, ELSEIF wasn't supported in VB
    <hr/>
    Code:
    Public Sub Poll_Keyboard()
       '-----------------------------------------------------------------------------
       '// Check for menu control keys, ESC terminates app, all other keys restore
       '   menu and cursor if they have been turned off. Proc includes key de bounce
       '-----------------------------------------------------------------------------
       Dim i As Long                                       'General working var
                                                              
       If GetAsyncKeyState(vbKeyEscape) Then               'Quit   (ESC)
          Terminate_App = True                             'Set flag
    
       '-----------------------------------------------------------------------------
       '// Check combination keys first
       '-----------------------------------------------------------------------------
       ElseIf GetAsyncKeyState(vbKeyControl) Then          'CTRL key down?
             If Popup_Insert.Enabled Then                  'Legal operation?
                If GetAsyncKeyState(vbKeyI) Then           'CTRL+I Insert
                   Call Popup_Insert_Click                 'Jump to proc
                   Exit Sub                                'Bail out
                End If
             End If
             
          If Popup_Save.Enabled Then                       'Legal operation?
             If GetAsyncKeyState(vbKeyShift) Then          'Shift?
                If GetAsyncKeyState(vbKeyS) Then           'Shift+CTRL+S Save As
                   Call Initiate_ROM_Save("Save As *.bin") 'Jump to proc
                   Exit Sub                                'Bail out
                End If
             End If
             
             If Not Run_ROM Then
                If GetAsyncKeyState(vbKeyN) Then           '(CTRL + N) New
                   Call New_ROM_Click                      'Jump to proc
                   Exit Sub                                'Bail out
                End If
       
                If GetAsyncKeyState(vbKeyO) Then           '(CTRL + O) Load
                   Call Load_ROM_Click                     'Jump to proc
                   Exit Sub                                'Bail out
                End If
             End If
             
          '//
          Else '(always allow open or load, if not running)
          '//
             If GetAsyncKeyState(vbKeyN) Then              '(CTRL + N) New
                Call New_ROM_Click                         'Jump to proc
                Exit Sub                                   'Bail out
             End If
       
             If GetAsyncKeyState(vbKeyO) Then              '(CTRL + O) Load
                Call Load_ROM_Click                        'Jump to proc
                Exit Sub                                   'Bail out
             End If
          End If
       '-----------------------------------------------------------------------------
       '// Function keys with no CTRL, all used except (10-12)
       '-----------------------------------------------------------------------------
       ElseIf GetAsyncKeyState(vbKeyF1) Then               '(F1) Show palette
          If Key_Pressed(vbKeyF1) = 0 Then                 'Key not held down?
             LED_Palette.Show                              'Show palette
             Key_Pressed(vbKeyF1) = 1                      'Set flag
          End If
             
       ElseIf GetAsyncKeyState(vbKeyF6) Then               '(F6) Next frame
          If Key_Pressed(vbKeyF6) = 0 Then                 'Key not held down?
             Adj_Button = 0                                'Set flag
             Call Apply_Frame_Num_Adj                      'Jump to proc
             Key_Pressed(vbKeyF6) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF7) Then               '(F7) Previous frame
          If Key_Pressed(vbKeyF7) = 0 Then                 'Key not held down?
             Adj_Button = 1                                'Set flag
             Call Apply_Frame_Num_Adj                      'Jump to proc
             Key_Pressed(vbKeyF7) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF8) Then               '(F8) Next group
          If Key_Pressed(vbKeyF8) = 0 Then                 'Key not held down?
             Adj_Button = 4                                'Set flag
             Call Apply_Group_Num_Adj                      'Jump to proc
             Key_Pressed(vbKeyF8) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF9) Then               '(F9) Previous group
          If Key_Pressed(vbKeyF9) = 0 Then                 'Key not held down?
             Adj_Button = 5                                'Set flag
             Call Apply_Group_Num_Adj                      'Jump to proc
             Key_Pressed(vbKeyF9) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF5) Then               '(F5) Run
          If Key_Pressed(vbKeyF5) = 0 Then                 'Key not held down?
             Call Run_Click                                'Jump to proc
             Key_Pressed(vbKeyF5) = 1                      'Set flag
          End If
          
       ElseIf GetAsyncKeyState(vbKeyF2) Then               '(F2) Pause
          If Key_Pressed(vbKeyF2) = 0 Then                 'Key not held down?
             Call Pause_Click                              'Jump to proc
             Key_Pressed(vbKeyF2) = 1                      'Set flag
          End If
          
       ElseIf GetAsyncKeyState(vbKeyF3) Then               '(F3) Reset
          If Key_Pressed(vbKeyF3) = 0 Then                 'Key not held down?
             Call Reset_Click                              'Jump to proc
             Key_Pressed(vbKeyF3) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF8) Then               '(F8) Jump to
          If Not Key_Pressed(vbKeyF8) Then                 'Key not held down?
             Call Jump_To_Frame_Click                      'Jump to proc
             Key_Pressed(vbKeyF8) = 1                      'Set flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyF9) Then               '(F9) Dump
          If Key_Pressed(vbKeyF9) = 0 Then                 'Key not held down?
             Call Dump_Click                               'Jump to proc
             Key_Pressed(vbKeyF9) = 1                      'Set key flag
          End If
       
       ElseIf GetAsyncKeyState(vbKeyDelete) Then           '(Del) All Off
          If Total_Frames <> 0 Then                        'Legal operation?
             If Key_Pressed(vbKeyDelete) = 0 Then          'Key not held down?
                Call All_Off_Click                         'Jump to proc
                Key_Pressed(vbKeyDelete) = 1               'Set flag
             End If
          End If
       '-----------------------------------------------------------------------------
       Else '// Any other key press restores menu & cursor (if switched off)
       '-----------------------------------------------------------------------------
          If Not Menu.Visible Then
             For i = 0 To 255                              'Test for keys
                 If GetAsyncKeyState(i) Then               '
                    Menu.Visible = True                    'Restore
                    Title.Visible = True                   '
                    Credits.Visible = True                 '
                    Call ShowCursor(True)                  'Mouse pointer
       '//
                    If Palette_Active Then                 'Palette visible prior?
                       LED_Palette.Show                    'Restore it
                    End If                                 '
                    Exit For                               'Bail out (no time wasted)
                 End If
             Next
          End If
       End If
       '-----------------------------------------------------------------------------
       '// Reset flags if keys are up
       '-----------------------------------------------------------------------------
       For i = 0 To 255                                    'Scan through all keys
           If GetAsyncKeyState(i) = 0 Then                 'Key held down?
              Key_Pressed(i) = 0                           'Reset flag if not
           End If                                          '
       Next                                                '
    End Sub
    Last edited by T.Jackson; - 9th May 2007 at 06:48.

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    A billion and a half plus 2 ways of doing things...yes...
    That 2nd code chunk looks an awful lot like, and in this case could be replaced by, a 'Select Case/End Select' block.
    EDIT: But, 'Select Case' is limited to one parameter, an ELSEIF would open that up quite a bit.

  3. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    As far as I know it already does. (just not all in one word)
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        endif
    endif
    _
    DT

  4. #4
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    And in some forms, literally KILLS free flash space...

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


    Did you find this post helpful? Yes | No

    Post

    That's not the same. True ELSEIF structure will exit out of the nest as soon as it hits the first true condition. Same as Select Case.

  6. #6
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    But PBP doesn't have the virtually (pun intended) unlimited stack space like Windows does.
    Gotta draw the line somewhere I suppose.

  7. #7
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by skimask View Post
    And in some forms, literally KILLS free flash space...
    No difference, no additional code space.

    Quote Originally Posted by T.Jackson View Post
    That's not the same. True ELSEIF structure will exit out of the nest as soon as it hits the first true condition. Same as Select Case.
    No difference. That's what it does.

    Added: No additional Stack space either.

    _
    Last edited by Darrel Taylor; - 9th May 2007 at 09:39. Reason: Stack
    DT

  8. #8
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    What I'm saying is that multiple IF/THEN statements:
    IF this then
    that
    ENDIF
    IF this then
    that
    ENDIF

    made back-to-back-to-back, takes more flash space than successive IF/THEN statements:
    If this then
    if this then
    if this then
    that
    endif
    endif
    EndIf

    I had to use the successive version of the IF/THEN vs. the back-to-back version in my MP3 player in a number of places (no way around it due to how the program was set up, either it was bad style or I just had too much going on to keep tabs on, just the nature of the program's complexity). Anywhos...when I changed everything over to the successive type, I saved a load of code space. I never did check in to why I saved as much space as I did, it just did, and I'm happy.

    As far as stack space goes, are you saying that there aren't any calls involved with doing an if/then?

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    As far as I know it already does. (just not all in one word)
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        endif
    endif
    It's not the same if a multitude of ELSEIF is required ...

    Code:
    IF Condition then
        Something
    else 
        if Condition2 then 'ELSEIF 1
            something else
        endif
    
       '// Even if ELSEIF 1 is true then we still validate this argument  
       if Condition2 then 'ELSEIF 2
            something else
        endif
    
       '// Likewise, even if ELSEIF 2 is true then we still validate this argument  
        if Condition3 then 'ELSEIF 3
            something else
        endif
    endif
    I guess you could have a GOTO in each block to exit out of the nest - but as I said before, true ELSEIF would make a nice addition to PBP.
    <hr/>

  10. #10
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    It'll work. You just need to add the next condition in the last one's ELSE clause.
    Code:
    IF Condition then
        Something
    else 
        if Condition2 then
            something else
        else
            if Condition3 then
                even more
            else
                if Condition4 then
                   4's good
                else
                    this is the final ELSE, if none of the others match
                    it ends up here
                endif
            endif
        endif
    endif
    Quote Originally Posted by skimask
    As far as stack space goes, are you saying that there aren't any calls involved with doing an if/then?
    Correct. If/Thens don't use the stack. They use GOTO's only.

    Added: There is no limit to the "Nested" levels of IF/THEN's.
    _
    Last edited by Darrel Taylor; - 9th May 2007 at 18:25. Reason: Nested Levels
    DT

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


    Did you find this post helpful? Yes | No

    Post

    O.K. I agree that to be logically equivalent to ELSEIF. But there's one downside, how do you plan on indenting 20 or more nested arguments?
    But, you have clearly illustrated just how easy it would be for MELABS to implement support for ELSEIF. PBP already has the raws required.
    Last edited by T.Jackson; - 10th May 2007 at 03:38.

  12. #12
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    no problem, i use a dual screen video card and two monitor
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  13. #13
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson
    how do you plan on indenting 20 or more nested arguments?
    That's just the way I format things.
    You dont have to do it that way.

    Here's one that skimask will like. (lottsa colons)
    Code:
    IF Condition  then
        Something
    else:IF Condition2  then 
        something else
    else:if Condition3  then
        even more
    else:if Condition4  then
        4's good
    else
        this is the final ELSE, if none of the others match
        it ends up here
    endif:endif:endif:endif
    DT

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


    Did you find this post helpful? Yes | No

    Post

    You're missing the point. While I agree that what you're saying will indeed do the same job (regardless of how you format it) there's still more effort from the programmer that's required. There's additional thought process along with extra typing. And, I have a sneaking suspicion that traditional ELSEIF structures might be somewhat better optimized.

  15. #15
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Actually, I think you are missing the point.

    Haven't you noticed...
    meLabs doesn't add things anymore.

    Last thing a saw get added was REPEAT..UNTIL.
    Not sure but maybe that was 2004. Version 2.44

    It's either learn how to use what you have.

    Or sit around wishing it were different.
    Even though it already does exactly what you want.

    _
    DT

  16. #16
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    When would someone have to use black pepper instead of red pepper?

    They are both hot, the color is different (this could fit somewhere else though).

    ------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  17. #17
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Last thing a saw get added was REPEAT..UNTIL.
    Not sure but maybe that was 2004. Version 2.44
    no it's false , the last major add was in 2.47
    Adds HSER_SPBRGH and HSER2_SPBRGH defines for PIC18Xxxxx.


    I don't know for others, but before having a 20 nested IF-THEN-ELSEIF structure, i would use something else... but it's me.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Post

    I"ve had PBP since about 2002. To my knowledge, no one in Australia is selling it anymore. Think I paid something like about $550 for it bundled together with a couple of 16f84's

  19. #19
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    and then ?
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by mister_e View Post
    and then ?
    And then I started developing PIC-Based projects and people began to get these crazy ideas in their heads that I had inventions. I'd like a full refund on my PBP purchase thanks. Where's the complaints department?

  21. #21
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    Quote Originally Posted by T.Jackson View Post
    I"ve had PBP since about 2002. To my knowledge, no one in Australia is selling it anymore. Think I paid something like about $550 for it bundled together with a couple of 16f84's
    Looks like you got took

    http://www.dontronics-shop.com/produ...roductid=16216

    Best Regards,
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

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


    Did you find this post helpful? Yes | No

    Post

    I think things tend to be a bit cheaper if you buy them off the net. I think also that PBP has dropped a bit in price over recent years.

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


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by T.Jackson View Post
    I"ve had PBP since about 2002. To my knowledge, no one in Australia is selling it anymore. Think I paid something like about $550 for it bundled together with a couple of 16f84's
    What is your point?

    And the price today is about the same as it was in 2000. (to the best of my memory)
    Dave
    Always wear safety glasses while programming.

  24. #24
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by mackrackit View Post
    What is your point?

    And the price today is about the same as it was in 2000. (to the best of my memory)
    Yep, PBP still costs $250USD, and I bought it back in late '98, still got the receipt. I guess that's about $301AUD, which, with the extra 'F84's and a board or two, might come up to around $550 or so.

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


    Did you find this post helpful? Yes | No

    Post

    Quote Originally Posted by skimask View Post
    Yep, PBP still costs $250USD, and I bought it back in late '98, still got the receipt. I guess that's about $301AUD, which, with the extra 'F84's and a board or two, might come up to around $550 or so.
    The Australian dollar is currently much stronger than it was back in 98. Back then, general rule of thumb was about double. $250 USD equated to about $500 AUS.

  26. #26
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,803


    Did you find this post helpful? Yes | No

    Default

    And finally is Melabs going to read your wishes and do something about it or are we reading the wishes only by ourselves and waisting time?

    Sure it is a good product doing what exactly is specified to do. And that's it.

    If they are going to develop it to compete other similar products, is something that only the team of the company knows and nobody else. In my humble opinion, the product has reached the end of its life and only new devices may be added for the future releases. A major upgrade would lead to a different product especially to be compatible with Vista. So...

    Ioannis

  27. #27
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I've said this (in various ways) before, but I'll repeat it again…

    You buy a screwdriver for your toolkit. It screws really well and works as advertised – it screws those screws without damaging their heads and leaves a professional clean result. Over time, the screw manufacturers change the head to a Philips, or a Torx or a Star or a Hex. And in response that original screwdriver manufacturer brings out a new tip that's compatible, so your screws can still be screwed professionally and cleanly.

    Meanwhile, other manufacturers have brought out Ratchet Screwdrivers and Cordless Screwdrivers, and although those other screwdrivers for sure claim to be quicker or easier to use with more features like textured grip handles, but sometimes they also mess up the heads of those screws and really they might not leave a solid professional job, although admittedly everyone can see they're quicker and easier to use especially for the inexperienced or hobbyist or DIYer.

    Meanwhile, that trusty old screwdriver in the bottom of the toolbox just goes on and on, doing not only the job it was originally bought to do, but doing it with a lot of the newer kinds of screws that have come onto the market.

    Now I'm talking about a screwdriver here, but you can read into it any way you want.

    Some folks just get on with it, some folks just whinge…

  28. #28
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Wink whinge

    Quote Originally Posted by Melanie View Post
    ...some folks just whinge…
    Hey, I had to look-up (Google) whinge.
    Even my spell checker hic-cupped on it.

    Where did I find it, first Google hit?
    The American Heritage Dictionary of the English Language!

    I am now adding it to my everyday vocabulary., as I have also added whilst and other useful verbiage.
    Other North Americans, think I talk funny. (except mister_e)

    Thanks,
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

  29. #29
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    You don't want to hear me A perfect mix of bad and pretty bad English + Quebec French accent

    http://wsu.edu/~brians/errors/errors.html#errors
    Last edited by mister_e; - 12th May 2007 at 18:52.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  30. #30
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Adam - Start by junking Websters dictionary (together with all his miss-spellings). I always harboured the thought that the good folks of New England were ready to adopt the Queens English proper and rejoin the Commonwealth. Perhaps that was the real reason for the Queens reconnoiter last week...

  31. #31
    Join Date
    Apr 2006
    Location
    New Hampshire USA
    Posts
    298


    Did you find this post helpful? Yes | No

    Default international forum

    Oh, that explains why the Queen visited.
    When I heard she was coming to America, I started hiding all the tea!
    Thought it was a tax collection expedition.

    It really is nice to see all the different spellings and word uses in this international forum. Not just the misspellings, which are fun too. The phrases that are very close to our local vernacular, remind us where we come from.

    BTW - The spelling differences are because, we shaved letters out of the Queens English, so we could recycle them into new words! (less code space too)
    Consider my Webster’s dictionary junked.

    Cheers,
    -Adam-
    Ohm it's not just a good idea... it's the LAW !

Similar Threads

  1. config bits
    By brianD in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 9th February 2010, 13:45
  2. Setting up internal clock correctly?
    By JohnM in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th March 2008, 20:29
  3. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  4. Bootloader and Instant Interrupts Atn:_DT_
    By Josuetas in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 16th May 2007, 01:59
  5. PortE problems (PIC18F4455)
    By RubenR in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 12th July 2006, 15:26

Members who have read this thread : 1

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