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!

How to evaluate (EVAL) only a part of a block ? 1

Status
Not open for further replies.

Manuch

Programmer
May 6, 2022
16
IT
Good morning,

I'm checking dates, day per day, against a cursor of festive days.
I would like to write a dynamic IF, like this:

If _calendar.DayType<ind> == 3 Then
(expected output for the engine, with ind=1: "If _calendar.DayType1 == 3 Then")

Where ind is the dynamic day of the week that I have to check in my loop.
I don't want to EVAL (or &) the whole IF block if possible, but only the row (IF ...) where I have the dynamic value.

I tried (with DATE()+1 for tests)

IF &('_calHonda.DayType' + ALLTRIM(TRANSFORM(DOW(DATE()+1)))) == 3 THEN

and similars, nothing


I tried to just print the content of the cursor, dynamically:

? &('_calHonda.DayType' + ALLTRIM(TRANSFORM(DOW(DATE()+1))))

But this gives an error too.


If I write the whole IF block inside a string, from begin to EndIf, and evaluate the string, it's probably going to work, like it's supposed to do, but I don't really like this idea very much.
Is there a way to EVAL only the row I need?

Thank you very much.
 
Hi

I think you would probably be right to use an EVALUATE() in this instance

Code:
IF EVALUATE("_calendar.DayType"+ALLTRIM(TRANSFORM(DOW(DATE()+1))))+"=3")
  && do something
ELSE
  && do something else
ENDIF

This assumes the DayTypeN field is a numeric otherwise

Code:
IF EVALUATE("_calendar.DayType"+ALLTRIM(TRANSFORM(DOW(DATE()+1))))+"='3'")
  && do something
ELSE
  && do something else
ENDIF


Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Thank you so much Griff, exactly what I was looking for, works like a charm.

Before you answered I added an EVAL to assign the content of the cursor on a variable and then checked the variable on the IF below, because I didn't know you can use EVAL in conjunction with "real" code, but your solution is way better, thanks a lot, have a great day.
 
Likewise

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.

There is no place like G28 X0 Y0 Z0
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top