Operating System - OpenVMS
1827932 Members
2104 Online
109973 Solutions
New Discussion

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

 
Martin Slimmer
Advisor

VMS COM: IF cur_hour .eq. num1 or num2 failing

Okay, I've googled and searched everywhere I can find. I need certain logic to execute if it is 7 AM or 7 PM (or other particular hours), but this is part of the command that is failing. When I execute this at 2 PM, it acts like it's 7 AM or 7 PM. Can someone point me to what I'm doing incorrectly? I'm fairly new to COM shell programming, so be gentle.. :)

Thanks,
- Martin

$!**********************************
$! Run @ 7 AM or 7 PM, based on cur_hour
$!*****************************************
$ if (cur_hour .eq. 7) .Or. (cur_hour .eq. 19) then
$ write sys$output cur_hour
14

10 REPLIES 10
Karl Rohwedder
Honored Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Is this a linewrap or is the WRITE... on 1 separate line?

$ if (cur_hour .eq. 7) .Or. (cur_hour .eq. 19)
$ Then
$ write sys$output cur_hour
$ endif

regards Kalle
Martin Slimmer
Advisor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

The "write" is on a separate line - however, the "then" is on the same line as the "IF" statement.
Thomas Ritter
Respected Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Maybe...

$!**********************************
$! Run @ 7 AM or 7 PM, based on cur_hour
$!*****************************************
$ cur_hour = f$cvtime(,,"hour")
$ if (cur_hour .eq. 7) .Or. (cur_hour .eq. 19)
$ then
$ write sys$output cur_hour
$ endif

Heinz W Genhart
Honored Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Hi Martin

how do you define the symbol cur_hour ?


Try this (maybe)

$ cur_hour = f$cvtime("",,"hour")
$ if (cur_hour .eq. 7) .Or. (cur_hour .eq. 19) then write sys$output cur_hour

You can get help about the lexical f$cvtime with

$ help lex f$cvtime

Hope that helps

Regards

Heinz
Martin Slimmer
Advisor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Well, turns out my problem was further down in the query... no points awarded.. sorry. But this is a great place to get great answers, everyone - thanks!
Martin Slimmer
Advisor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Problem was further down past the "IF" statment.
Jim_McKinney
Honored Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

> The "write" is on a separate line - however, the "then" is on the same line as the "IF" statement.

As written, the "IF" statement has a null argument and does nothing. In order to associate the "write" statement with the "IF" statement you need to append a "-" continuation character to the "IF" command line (or alternatively place the entire command - "if" and "write" - on a single line).

$ if (cur_hour .eq. 7) .Or. (cur_hour .eq. 19) then -
write sys$output cur_hour

Or use the block structure that others have suggested. Either will work. The block structure that others have suggested will permit you to execute multiple commands between the

$ if
$ then
$ ! insert
$ ! command
$ ! lines
$ ! here
$ endif

rather than a single conditional command when the block structure is not used.
Robert Gezelter
Honored Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Martin,

Not to mention that if "cur_hour" is the direct output of F$CVTIME, then it is in a string format, not an integer.

- Bob Gezelter, http://www.rlgsc.com
Lawrence Czlapinski
Trusted Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Bob, The check against an integer does work.
ASDEV1» $ cur_hour = f$cvtime(,,"hour")
ASDEV1» write sys$output cur_hour
16
ASDEV1» if cur_hour .eq. 16 then write sys$output cur_hour
16
ASDEV1»
Lawrence
Robert Gezelter
Honored Contributor

Re: VMS COM: IF cur_hour .eq. num1 or num2 failing

Lawrence,

So it does. Strange. I cannot reproduce the case at this instant, but I seem to remember chasing a client problem where the answer was that the client had used .EQ. instead of .EQS. and was surprised.

I do not have the precise case at my fingertips (and my quick attempt to reproduce does not coincide with my memory), so I must be missing something.

My apologies.

- Bob Gezelter, http://www.rlgsc.com