Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ElseIf This and This then

Status
Not open for further replies.

DMS500Tech

Technical User
Dec 22, 2004
39
US
Here is a snippet of code that I am having a little trouble finding a compliment command or rearranging the logic to accomplish my needs.
The first IF statement is straight forward and works.
The ElseIF statement that needs to come next is giving me problems. r1column1 and r2column1 need to both be true for the script to branch to column2 or either one be false to proceed to the else statement.

Preceeding this are the declrations and the termgets and they seem to be okay so far.

If r1column1 = "."
goto column2 ;......................no alarms move to next column
Elseif r1column1 = c1change1 and (&) r2column1 = c1change2
goto column2 ;.......................no change next column
Else
Alarm1 = r1column1 ;.................assign to variable to remove extra characters
call "and so on"

after this are the called proceedures to deal with the next columns and alarms.
 
Unfortunately I don't think there's a clean and elegant way to do this, but I've been up for a while at this point. Maybe the best thing to do would be to use a nested if like below to check the operations in the first elseif statement (assuming all variables are string):

if strcmp r1column1 c1change1
if strcmp r2column1 c1change2
;both are true
else
;not true
endif
else
;not true
endif

Where I have the comment above, you could set a value in a variable, say 1. On the two comments above where I have not true, you could set that same variable to zero so it is always calculated. You would then replace the elseif mess in your original code with a simple:

elseif variablename

Does that make sense? I'm heading to bed now, so shout if it doesn't.

 
Parenthesis are a good way to make it elegant IMHO
Below is a mini program, which compiles, works and outlines the elseif scenario properly. I think it's what you were after


#define CRLF "`r`n"

proc main
integer i = 1
integer j = 1
if ( ( j = 0 ) & ( i = 0 ) )
println ( "if case" )
elseif ( ( j = 1 ) & ( i = 1 ) )
println ( "elsif works fine for me" )
endif
endproc

proc println
param string sText
string sStringToPrint = ""
strcat sStringToPrint sText
strcat sStringToPrint CRLF
termmsg sStringToPrint
endproc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top