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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If stricmp sString "String1" OR "String2"

Status
Not open for further replies.

pronei

Vendor
Mar 11, 2008
1,010
US
How do I script the following OR command to check Excel R3C1 = "One" OR "Two"

I can NOT get OR to work when checking multiple possibilities for string sSite

proc main
string sSite,sRow
integer iRow = 3 ;Row 3 of Excel
integer iSite = 1 ;Column 1 of Excel
long DDEChan
ddeinit DDEChan "excel" "sheet1"

strfmt sRow "R%dC%d" iRow iSite
dderequest DDEChan sRow sSite

if stricmp sSite "One" || sSite "Two"
usermsg "Yeah, finally got OR to work on Strings!"
else
usermsg "Using OR to check string values sucks!"
endif
endproc
 
You could try using switch:

Code:
switch sSkip
	case "s"
	endcase
	case "n"
	endcase
	default
		sdlgmsgbox "" "Only s or n allowed" stop ok iIgnore
		exit
	endcase
endswitch

or elseif

Code:
if strfind DayOfWeek "MON"
              DayOfWeek1 = "LNM"
      elseif strfind DayOfWeek "TUE"  
              DayOfWeek1 = "STD"
      elseif strfind DayOfWeek "WED"
                DayOfWeek1 = "VDC"
      elseif strfind DayOfWeek "THU"
                DayOfWeek1 = "SGT"
      elseif strfind DayOfWeek "FRI"
                DayOfWeek1 = "EQH"
      elseif strfind DayOfWeek "SAT"
              DayOfWeek1 = "RZS"
      elseif strfind DayOfWeek "SUN"
              DayOfWeek1 = "RTM"
   endif
 
As far as I know you cannot use the "OR" function when comparing strings. You need to use a nested IF. This code will do what you want.

proc main

string sSite,sRow
integer iRow = 3 ;Row 3 of Excel
integer iSite = 1 ;Column 1 of Excel
long DDEChan

ddeinit DDEChan "excel" "sheet1"
strfmt sRow "R%dC%d" iRow iSite
usermsg srow
dderequest DDEChan sRow sSite
if strnicmp sSite "One" 3
usermsg "sSite = One"
else
if strnicmp sSite "Two" 3
usermsg "sSite = Two"
else
usermsg "sSite <> One or Two"
endif
endif
endproc
 
Yeah I've used nested ifs, and it works fine like that, I just wanted shorter, cleaner code.

So I'd assume in aspect you can only use && || with integers? Does it work with floats?
 
Shorter/Cleaner code is always the goal. Unfortunately, in this case I know of no way around it.

&& and || does work with both integers and floats.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top