- Michael,

At 2005/01/05 17:45 -0500 you wrote:

>I have a clip that asks for a month and the number of the first Sunday,

The following two clips demonstrate two ways to find out whether a month is odd or even. The first clip finds it out using this line:

>then sets up predefined dates for the month. I want to test for whether

>it is an odd month or even month so that the clip inserts event A or

>event B. The clip prompts me to pick the month, but I can't figure out

>how to test for more than one month at a time. The online help does not

>seem to explain how to test for A or B or C, then do one thing.

>

>The second line does not work, but I don't know the correct syntax.

>

>^!Set %month%=^?[Month for

>events?=Jan.|Feb.|Mar.|Apr.|May|June|July|Aug.|Sept.|Oct.|Nov.|Dec.]

>^!If ^%month% = "Jan."|"Mar." ^!Info This is odd month

^!If ^$Calc(^%MonthNumber% div 2;9)$ <> ^$Calc(^%MonthNumber% / 2;9)$ IsOdd else IsEven

The div operator returns just the integer part of the result (that is, 5 div 2 = 2, instead of 2.5).

The forward slash "/" operator returns the real result (that is 5 div 2 = 2.5).

Therefore, if they don't match, we have an odd number; while if they are the same, the number is even.

Since here we are dealing with a limited number of possibilities, we know that the possible odd numbers are contained between 1 and 11, so we can do without the previous calculation, saving CPU cycles, and change the line to simply read:

^!If ^$StrPos("^%MonthNumber%";"1357911";True)$ > 0 IsOdd else IsEven

Then, if the number is found in the "1357911" string, we know it is an odd number. You can use commas, if preferred, to make the numbers easier to read: "1,3,5,7,9,11". In this case, there is no difference using one string or the other.

;======== Start ========

H="Month Odd or Even (using Calc)"

; *:---- start long line: ----

^$* WARNING: This clip can contain 2 broken long lines if this line is broken.You can DELETE THIS WARNING LINE after making sure lines were not split.

; *.---- end long line ----

; @ 20050105_1904

; *:---- start long line: ----

^!Set %ChoiceList%=Jan.|Feb.|Mar.|Apr.|May|June|July|Aug.|Sept.|Oct.|Nov.|Dec.

; *.---- end long line ----

^!SetListDelimiter "|"

^!Set %month%=^?{(H=12)Month for events?==^%ChoiceList%}

^!Set %i%=^$StrPos("^%month%";"^%ChoiceList%";True)$

^!Set %MonthNumber%=^$Calc(^%i% div 5 + 1;0)$

^!Set %msg%="Month ^%MonthNumber%, ^%month%, is "

; *:---- start long line: ----

^!If ^$Calc(^%MonthNumber% div 2;9)$ <> ^$Calc(^%MonthNumber% / 2;9)$ IsOdd else IsEven

; *.---- end long line ----

:IsOdd

^!Set %msg%=^%msg%ODD

^!Goto displayresult

:IsEven

^!Set %msg%=^%msg%EVEN

:displayresult

^!Info [L]^%msg%

H="Month Odd or Even - Faster (Using hard-coded string)"

; *:---- start long line: ----

^$* WARNING: This clip can contain 1 broken long lines if this line is broken.You can DELETE THIS WARNING LINE after making sure lines were not split.

; *.---- end long line ----

; @ 20050105_1914

; *:---- start long line: ----

^!Set %ChoiceList%=Jan.|Feb.|Mar.|Apr.|May|June|July|Aug.|Sept.|Oct.|Nov.|Dec.

; *.---- end long line ----

^!SetListDelimiter "|"

^!Set %month%=^?{(H=12)Month for events?==^%ChoiceList%}

^!Set %i%=^$StrPos("^%month%";"^%ChoiceList%";True)$

^!Set %MonthNumber%=^$Calc(^%i% div 5 + 1;0)$

^!Set %msg%="Month ^%MonthNumber%, ^%month%, is "

^!If ^$StrPos("^%MonthNumber%";"1357911";True)$ > 0 IsOdd else IsEven

:IsOdd

^!Set %msg%=^%msg%ODD

^!Goto displayresult

:IsEven

^!Set %msg%=^%msg%EVEN

:displayresult

^!Info [L]^%msg%

;========= End =========

Best regards,

Ramon Silvera

Author of ClipWriter and InSight

http://www.dataomega.com/insight

http://ptools.home.att.net/ClipWriter/cw.htm - Michael Frascinella wrote:
> Notetabbers,

; For month as a number 1-12

>

> I have a clip that asks for a month and the number of the first Sunday,

> then sets up predefined dates for the month. I want to test for whether

> it is an odd month or even month so that the clip inserts event A or

> event B. The clip prompts me to pick the month, but I can't figure out

> how to test for more than one month at a time. The online help does not

> seem to explain how to test for A or B or C, then do one thing.

>

> The second line does not work, but I don't know the correct syntax.

>

> ^!Set %month%=^?[Month for

> events?=Jan.|Feb.|Mar.|Apr.|May|June|July|Aug.|Sept.|Oct.|Nov.|Dec.]

> ^!If ^%month% = "Jan."|"Mar." ^!Info This is odd month

^!IF ^$Calc("^%Month% mod 2;0")$ = 0 MonthEven Else MonthOdd

; For month as a short string.

^!Set %OddMonths%="Jan|Mar|May|July|Sept|Nov"

^!If ^$StrPos("^%Month%";"^%OddMonths%";0)$ >0 MonthOdd Else MonthEven

(Note: The later example could have been made into one line, but I

generally recommend breaking commands up into pieces in order to

avoid long lines whenever possible.)

Wayne VanWeerthuizen - Wayne,

I think I almost understand your solution but it's disappointing that

Notetab can't handle Booleans in an If statement the way it does with

the Find statement. **Feature request**

When I used to write command procedures that ran on VMS, I could test

for multiple conditions with the .or. or the .and. operators. For example,

If (month = "jan") .or. (month = "mar") then goto oddmonth

Help me with the following.

Example 1:

; For month as a number 1-12

^!IF ^$Calc("^%Month% mod 2;0")$ = 0 MonthEven Else MonthOdd

Your first example uses the ^$Calc statement and assumes that the

%month% variable stores a number (1-12). The online help explains not

much about a lot of math functions and MOD is one of them. What is the

meaning of the expression inside the Calc parentheses and what does it

mean to test if the expression equals zero?

Example 2:

; For month as a short string

^!Set %OddMonths%="Jan|Mar|May|July|Sept|Nov"

^!If ^$StrPos("^%Month%";"^%OddMonths%";0)$ >0 MonthOdd Else MonthEven

In the second example, %month% is a variable containing the month the

user selects and %oddmonths% is a comparison string. What is the meaning

of the vbars? It looks like an array but ^!SetArray is the statement to

do that, right? Is %oddmonths% just a simple text string of all the odd

months and StrPos is looking for the string the user selected?

^!StrPos looks for the substring %month% in the string %oddmonths% but

what does it mean if the value is greater than zero? Or maybe I should

ask when does that result = 0?

Yours,

Michael F

Working from home

-©¿©-

~

******************

Never Forget

September 11, 2001

******************

[Non-text portions of this message have been removed] - Michael Frascinella wrote:
> Wayne,

Some of this is covered in a tutorial I began work a couple years ago.

>

> I think I almost understand your solution but it's disappointing that

> Notetab can't handle Booleans in an If statement the way it does with

> the Find statement. **Feature request**

I never did finish it. If anyone wants to help me update/complete it, it

would be much appreciated.

Look for the file "NoteTab Tutorial Control Structures v003.otl"

in the yahoo groups file area:

http://groups.yahoo.com/group/ntb-clips/files/

Again, note that several sections of the outline are not complete, and

some of the clip examples filled-in yet.

> When I used to write command procedures that ran on VMS, I could test

mod means modulo, which is basically the remainder after division.

> for multiple conditions with the .or. or the .and. operators. For example,

>

> If (month = "jan") .or. (month = "mar") then goto oddmonth

>

> Help me with the following.

>

> Example 1:

>

> ; For month as a number 1-12

> ^!IF ^$Calc("^%Month% mod 2;0")$ = 0 MonthEven Else MonthOdd

>

> Your first example uses the ^$Calc statement and assumes that the

> %month% variable stores a number (1-12). The online help explains not

> much about a lot of math functions and MOD is one of them. What is the

> meaning of the expression inside the Calc parentheses and what does it

> mean to test if the expression equals zero?

For example, 27 divided by 5 is 5 remainder 2. So 27 mod 5 = 2.

X mod 2 is zero whenever X is even.

X mod 10 is zero if X is a multiple of ten.

> Example 2:

In the example the vbars are merely decorative. They could be

>

> ; For month as a short string

> ^!Set %OddMonths%="Jan|Mar|May|July|Sept|Nov"

> ^!If ^$StrPos("^%Month%";"^%OddMonths%";0)$ >0 MonthOdd Else MonthEven

>

> In the second example, %month% is a variable containing the month the

> user selects and %oddmonths% is a comparison string. What is the meaning

> of the vbars? It looks like an array but ^!SetArray is the statement to

> do that, right? Is %oddmonths% just a simple text string of all the odd

> months and StrPos is looking for the string the user selected?

changed to spaces, or even removed entirely. In other situations,

they could help prevent extraneous matches, such as "arm" within

"MarMay".

> ^!StrPos looks for the substring %month% in the string %oddmonths% but

StrPos returns the character position within second string where the

> what does it mean if the value is greater than zero? Or maybe I should

> ask when does that result = 0?

first string is found. It returns 0 only if the first string is not

found within the second. StrPos returns 1 if the second string begins

with the first. In example above ^$StrPos("May";"^%OddMonths%";0)$

should return 9.