1. 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.
    Dismiss Notice

Using CASE in Oshonsoft

Discussion in 'Oshonsoft' started by camerart, Apr 27, 2017.

  1. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    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
     
  2. Superdat

    Superdat Member

    Joined:
    Mar 3, 2015
    Messages:
    114
    Likes:
    4
    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.
     
  3. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    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.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Superdat

    Superdat Member

    Joined:
    Mar 3, 2015
    Messages:
    114
    Likes:
    4

    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.
     
  6. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    469
    Likes:
    37
    in VB
    DIM Y&
    123
    Y = -(Y < 128) * (Y + 1) - (Y = 128) * 255 - (Y > 128) ' alternative
    goto 123
     

    Attached Files:

  7. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    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.
     
  8. Superdat

    Superdat Member

    Joined:
    Mar 3, 2015
    Messages:
    114
    Likes:
    4
    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.
     
  9. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,251
    Likes:
    911
    Location:
    Rochdale UK
    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



     
  10. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    469
    Likes:
    37
    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.
     
  11. Superdat

    Superdat Member

    Joined:
    Mar 3, 2015
    Messages:
    114
    Likes:
    4
    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.
     
  12. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    469
    Likes:
    37
    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
     
  13. camerart

    camerart Active Member

    Joined:
    Jun 12, 2008
    Messages:
    1,368
    Likes:
    11
    Location:
    Dorset UK.
    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.
     
  14. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    469
    Likes:
    37
    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
     

Share This Page