Menu

Passing Variables to subroutines called using "Case"

Help
viscomjim
2016-07-28
2016-07-28
  • viscomjim

    viscomjim - 2016-07-28

    Is it legit to pass variable data to a subroutine that is called using the Case statement as follows...

    select case Action
    case 1
        Data = ([word}ReadAN4 * 2)
        Sub1 25, 60, 144, Data as word
    case 2
        Data = ([word}ReadAN4 * 2)
        Sub1 25, 60, 144, Data as word
    case 3
        Data = ([word}ReadAN4 * 3)
        Sub2 25, 60, 144, Data as word
    case 4
        Data = ([word}ReadAN4 * 3)
        Sub2 25, 60, 144, Data as word
    end select
    

    What are the limitations with Case? I can only find single line stuff when using case and wondered if this the only way to use case.

    Thanks!!!

     
    • Anobium

      Anobium - 2016-07-28

      ... if action is 1, 2, 3 or 4 then all is good it will excute the case statements. Well.. nearly... 'Sub2 25, 60, 144, Data' is valid no need to define as a word... and if Data is dimensioned a word, then 'Data = ReadAD10 (AN4) * 2' is the correct method (with Dim Data as Word).

       
    • Anobium

      Anobium - 2016-07-28

      Multi - line statements are possible.

       
      • viscomjim

        viscomjim - 2016-07-28

        So multi line is good, how about passing varible data to a sub using the select case, are there any limitations there?

         
  • viscomjim

    viscomjim - 2016-07-28

    And can you do stuff like...

    select case Action
    case > 100
        Sub1
     case < 50
         Sub2
    
         etc, etc...
      end select
    
     

    Last edit: viscomjim 2016-07-28
    • Anobium

      Anobium - 2016-07-28

      Changed your mind?

       
      • Anobium

        Anobium - 2016-07-28

        Yes.

         
  • viscomjim

    viscomjim - 2016-07-28

    No, just want to clean up code and need to know if you can pass variable data from the select case for one part of the program and then see if you can do the great than and less than thing from a select case for another part of the program.

     
  • viscomjim

    viscomjim - 2016-07-28

    Can you do multiple tests on the select case like this...

    select case Action
        case > 6 and < 10
            Sub1
         case 10 or 12
             Sub2
    
          etc...
          end select
    
     
    • Anobium

      Anobium - 2016-07-28

      I am thinking ... a little bit of trial and error may help. Try these things, Add, some serial debug to see the results.

      But, essentially .. yes.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.