PDA

View Full Version : Multiple "AND"'s in select case?



polymer52
- 27th December 2009, 21:42
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)



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.



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

sayzer
- 28th December 2009, 07:33
This should work



Case is >= pvmin and is >= batt and is <= battmax

But this one seems to be better,


Case is >= pvmin
if pv >= batt and pv <= battmax then etc...

polymer52
- 28th December 2009, 11:40
This should work


Case is >= pvmin and is >= batt and is <= battmax

But this one seems to be better,


Case is >= pvmin
if pv >= batt and pv <= battmax then etc...



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

kevlar129bp
- 1st January 2010, 02:55
I got tripped up with this one too...
Needs to be along the lines of:


Case is >= pvmin
if (pv >= batt) AND (pv <= battmax) then etc...

Good luck and happy coding.

Chris

polymer52
- 1st January 2010, 19:10
Works great. Thanks guys.