PDA

View Full Version : ELSEIF Block Would be Good.



T.Jackson
- 9th May 2007, 07:34
Be great if PBP supported ELSEIF structure - something a bit like the following...



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/>


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

skimask
- 9th May 2007, 09:57
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.

Darrel Taylor
- 9th May 2007, 10:18
As far as I know it already does. (just not all in one word)

IF Condition then
Something
else
if Condition2 then
something else
endif
endif

_

skimask
- 9th May 2007, 10:23
And in some forms, literally KILLS free flash space...

T.Jackson
- 9th May 2007, 10:23
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.

skimask
- 9th May 2007, 10:26
But PBP doesn't have the virtually (pun intended) unlimited stack space like Windows does.
Gotta draw the line somewhere I suppose.

Darrel Taylor
- 9th May 2007, 10:32
And in some forms, literally KILLS free flash space... No difference, no additional code space.


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.

_

skimask
- 9th May 2007, 10:49
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?

T.Jackson
- 9th May 2007, 11:43
As far as I know it already does. (just not all in one word)

IF Condition then
Something
else
if Condition2 then
something else
endif
endif


It's not the same if a multitude of ELSEIF is required ...


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/>

Darrel Taylor
- 9th May 2007, 18:47
It'll work. You just need to add the next condition in the last one's ELSE clause.
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


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.
_

T.Jackson
- 10th May 2007, 04:21
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.

mister_e
- 10th May 2007, 04:37
no problem, i use a dual screen video card and two monitor :D

Darrel Taylor
- 10th May 2007, 06:32
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)
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

T.Jackson
- 10th May 2007, 06:54
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.

Darrel Taylor
- 10th May 2007, 07:10
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.

_

sayzer
- 10th May 2007, 08:51
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).

------------------

mister_e
- 10th May 2007, 16:17
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.
http://www.mister-e.org/Pics/ROFL

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.

T.Jackson
- 10th May 2007, 16:53
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

mister_e
- 10th May 2007, 20:59
and then ?

T.Jackson
- 11th May 2007, 06:40
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? ;)

paul borgmeier
- 11th May 2007, 06:57
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/product.php?productid=16216

Best Regards,

T.Jackson
- 11th May 2007, 07:36
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.

mackrackit
- 11th May 2007, 22:02
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)

skimask
- 11th May 2007, 22:52
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.

T.Jackson
- 12th May 2007, 06:59
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.

Ioannis
- 12th May 2007, 11:19
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

Melanie
- 12th May 2007, 12:15
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…

Pic_User
- 12th May 2007, 16:05
...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-

mister_e
- 12th May 2007, 19:48
You don't want to hear me :D A perfect mix of bad and pretty bad English + Quebec French accent :D

http://wsu.edu/~brians/errors/errors.html#errors

Melanie
- 13th May 2007, 22:10
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...

Pic_User
- 14th May 2007, 04:36
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.:D

Cheers,
-Adam-