Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Using CASE in Oshonsoft

Status
Not open for further replies.

camerart

Well-Known Member
Hi,
Some time ago I was helped with writing a program, by adding CASE into it. The program worked, and I didn't think about it anymore. CASE has just cropped up again, so I had a look at it.

Here is an example from the manual:
Dim x As Byte
loop:
Select Case x
Case 255
x = 1
Case <= 127
x = x + 1
Case Else
x = 255
EndSelect
Goto loop

If the manual had said that [CASE x] is a shorter way of saying:
[If it is the CASE is that if x = 255 then 'do something'] then I would have learnt how to use CASE, and remembered it.
Camerart
 
Hi
I see your post is a bit old, but ppl still read these things long afterwards.
I find some of the examples are just too clever. Sometimes I don't understand what it is trying to do, so I can't relate to the command/function.
I sometimes use Just Basic/BBC Basic to figure out what a function should do. That way you don't have to worry about any Micro Processor stuff.
 
Hi
I see your post is a bit old, but ppl still read these things long afterwards.
I find some of the examples are just too clever. Sometimes I don't understand what it is trying to do, so I can't relate to the command/function.
I sometimes use Just Basic/BBC Basic to figure out what a function should do. That way you don't have to worry about any Micro Processor stuff.
Hi S,
Are you asking a question?
I am programming Microprocessors, so i don't understand what you mean by [That way you don't have to worry about any Micro Processor stuff]
C.
 
Hi
No, not a question more a "I understand your confusion" and a suggestion if you want it. I sometimes browse the functions that are available especially the ones I haven't heard of to see what they can do, Case being one of them. So rather than thinking of how I might use it with a microprocessor, which at that point is tricky because I don't really understand what Case does, I use Just Basic/BBC. I find the examples in Basic programmers to be much better than those in Oshonsoft/GCB/JALV2. All you have to do is invent a few variables and assign values, then you can prove to yourself how Case works.
Once understood, you will know when and how to use it with a microprocessor.
 
in VB
DIM Y&
123
Y = -(Y < 128) * (Y + 1) - (Y = 128) * 255 - (Y > 128) ' alternative
goto 123
 

Attachments

  • Case_v_BinaryArithmetic.rar
    14.7 KB · Views: 241
Hi S and C,
I exclusivly use Oshonsoft and it's examples, and some times it is made more difficult by the wording. It's just a shorthand way of writing IFs and ENDIFs.
I'm sure natural programmers know the ins and outs of it, but I simply cut and paste such sections into my programs, as a practical solution for bad memory.
C.
 
in VB
DIM Y&
123
Y = -(Y < 128) * (Y + 1) - (Y = 128) * 255 - (Y > 128) ' alternative
goto 123
LOL strewth that's even harder to understand than the Oshonsoft verson!
Here is an example from Just Basic
num = 3
select case num
case 1
print "one"
case 2
print "two"
case 3
print "three"
case else
print "other number"
end select
You don't even need to run a program with JB, IMO it just explains it better. That said I've yet to find any practical use for CASE.
 
That said I've yet to find any practical use for CASE.
Its derived from the C switch statement... Very powerful because you can normally have multiple arguments

select case
case 1 to 5
Blah Blah​
case 6,7
Blahhhh​
case 8 to 12
bluurrr​
case else
ping​
end select


 
to find any practical use for CASE
you can setup a small event handles tree using CASE
e.g. evt.-s set flags that indicate there's smth. to process AND if the program structure is simple and some evt.-s have priority against some others there's no point setting everything up with complex interrupt structures while you can simply set the priorities by evt.-flag - CASE structure . . .
back in PM (past millennium) i used such to read DOS KB as some keys had byte code others word or double . . .
also a simple user-interactive graphics-display can utilize the CASE
e.c.
 
I'm not saying it doesn't have a use, just that I haven't found a use for it yet in any of my projects.
Ian's example is very similar to the one from JustBasic. Using "help" from other sources (i.e. not just Oshonsoft) can help with understanding.
I think I found the final piece needed to make ADC work with AtMega328P in a sample of Arduino code.
 
I would have learnt how to use CASE, and remembered it.
unless you're self educating - these things are explained in lectures/classes . . . even in syntax rules if you pay attention
though you may be right not after Win-XP SP-3 so April 21, 2008 -- they won't give a damn how any software can be used by novices
 
unless you're self educating - these things are explained in lectures/classes . . . even in syntax rules if you pay attention
though you may be right not after Win-XP SP-3 so April 21, 2008 -- they won't give a damn how any software can be used by novices
Hi C,
You appear to be far advanced in programming than I ever hope to be. I want to program PICs in the easiest way possible, only understanding the skeleton of how my programs work. I am also behind the times, as I only speak BASIC. CASE was pointed out to me, and as mentioned saved the need to keep writing IFs and ENDIFS, so as far as I know this is what I use it for.
C.
 
You appear to be far advanced in programming than I ever hope to be.
i barely program o_O . . . in these days (the main cause is no steady output platform -- changes every 3 2 5 y -- www even faster -- no such need/time to revise everything ((to ever more stupid)) inside that window) . . . got the interest of how compiler sees it
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top