Old classic If-Then...


Closed Thread
Results 1 to 17 of 17

Hybrid View

  1. #1
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115

    Default Old classic If-Then...

    I got a little confussed on this nested If-Then:

    Code:
    if level<=high_level then
    	if thermiko1=0 then
    		if thermistor1=0 then
    			if auto1=0 then
    				if onboard_an2<=pres_limit then
    					if pump=0 then
    						module_rel_out=1
    					else
    						module_rel_out=0
    					endif
    				endif
    			endif
    		endif
    	endif
    endif
    does make module_rel_out=1 but does not makes it 0 if the conditions (one or more) are not met.

    I am missing something but cannot figure what...

    Any help appreciated.
    Ioannis

  2. #2


    Did you find this post helpful? Yes | No

    Default

    You need to insert the ELSE statement for each IF. For example, if the first IF is not true, the code never gets to the ELSE ...=0

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    to execute this part...
    Code:
    if pump=0 then
    						module_rel_out=1
    					else
    						module_rel_out=0
    					endif
    ALL previous conditions have to be met.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    Simply pre-load the ELSE condition into the variable before entering the IF loop...
    Code:
    module_rel_out=0
    if level<=high_level then
    	if thermiko1=0 then
    		if thermistor1=0 then
    			if auto1=0 then
    				if onboard_an2<=pres_limit then
    					if pump=0 then module_rel_out=1
    					endif
    				endif
    			endif
    		endif
    	endif

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Hi, Ioannis

    Why not use an AND combination of your conditions.

    Karnaugh would LOVE your example.

    Try this little soft ... and ENJOY.

    Karnaugh Minimizer 2.0
    Copyright (c) 2002-2007 ShurikSoft.
    http://www.shuriksoft.com

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default

    Hi all and thanks for the replies.

    Alain: I tried with AND but got an error of too many variables. Indeed was long line!

    Melanie: That was what I did just before reading your post. Yes this works but was not appealing to me as an elegant solution.

    Steve & Tobias: Yes,I see now, after the morning cup of coffee that it never reached the ELSE statement.

    Thanks again to all.

    Ioannis

Similar Threads

  1. Classic
    By Haggar in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 18th April 2005, 09:57

Members who have read this thread : 0

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