Multiple "AND"'s in select case?


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52

    Default Multiple "AND"'s in select case?

    Does Select case not allow and's in one line?
    Here is a snippet.
    Even when all is true it ignores the first 2 lines.

    Background:
    pv = current photovoltaic voltage (varies 0-34v)
    pvhigh = voltage to turn on both grid tie inverter and battery charger (13.5v)
    pvmin = minimum pv voltage to shut down system (12.0v)
    batt = current battery voltage
    battmax = maximum battery voltage (13.2v)

    Code:
    Select Case pv			
        Case is >= pvmin and pv >= batt and pv <= battmax			
            gosub ChargeBatt	               'Turns on batt relay                   
    	Case is >= battmax and batt >= battmax			
        	gosub gridtie                      'Turns on inverter relay
        case is >=pvhigh                     
            gosub AllSystems                'Turns on both relays
    	Case else                          ' < pvmin. Turns off both relays
       	gosub standby
    end Select				' Resume here after case is executed
    Now if I delete the ands it will jump to the subs.

    Code:
    Select Case pv			
        Case is >= pvmin			
            gosub ChargeBatt	      'Turns on batt relay
    	Case is >= battmax		
        	gosub gridtie            'Turns on inverter relay
        case is >=pvhigh           
            gosub AllSystems      'Turns on both relays
    	Case else                  
       	gosub standby         ' < pvmin. Turns off both relays
    end Select				' Resume here after case is executed

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


    Did you find this post helpful? Yes | No

    Post

    This should work
    Code:
       Case is >= pvmin and is >= batt and is <= battmax
    But this one seems to be better,
    Code:
       Case is >= pvmin 
            if pv >= batt and pv <= battmax  then etc...
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    This should work
    Code:
       Case is >= pvmin and is >= batt and is <= battmax
    But this one seems to be better,
    Code:
       Case is >= pvmin 
            if pv >= batt and pv <= battmax  then etc...

    Thanks. I'll try that tonight when I get back home.

  4. #4
    Join Date
    Dec 2005
    Location
    Salt Lake City, Ut, USA
    Posts
    108


    Did you find this post helpful? Yes | No

    Default

    I got tripped up with this one too...
    Needs to be along the lines of:

    Code:
    Case is >= pvmin 
            if (pv >= batt) AND (pv <= battmax)  then etc...
    Good luck and happy coding.

    Chris

  5. #5
    Join Date
    Nov 2009
    Location
    Wagoner, USA
    Posts
    52


    Did you find this post helpful? Yes | No

    Default

    Works great. Thanks guys.

Similar Threads

  1. Using Nokia LCD
    By BobP in forum mel PIC BASIC Pro
    Replies: 300
    Last Post: - 3rd May 2018, 04:47
  2. Sony SIRC IR Issue
    By Ryan7777 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th August 2015, 08:10
  3. Write Onewire data toa I2C memory / read ASCI
    By Eugeniu in forum mel PIC BASIC Pro
    Replies: 67
    Last Post: - 16th November 2008, 19:19
  4. Crystalfontz LCD
    By jman12 in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 9th February 2007, 15:04
  5. Interrupt/timer not really interrupting...
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 22nd May 2005, 22:05

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