What is limit of Nested IF statement in MS Word? - ms-word

Is there any limit on how many nesting we can use in Nested IF statement in Microsoft Word?
Also, if limit can be different based on office version?

The nesting limit is 20 in all Word versions.

I know this is old, but this may help others. You only need ONE else statement at the end. There is no need to nest. Example:
{IF { MERGEFIELD LETTERCODE } = "A" "LETTER A TEXT HERE"
}{IF { MERGEFIELD LETTERCODE } = "B" "LETTER B TEXT HERE"
}{IF { MERGEFIELD LETTERCODE } = "C" "LETTER C TEXT HERE"
}{IF { MERGEFIELD LETTERCODE } = "D" "LETTER D TEXT HERE"
"ELSE DEFAULT LETTER TEXT HERE" }
I've done 80+ versions like this.

Related

Modify vscode snippet by regex: TitleCase and SNAKE_CASE

I have two questions for vscode snippets+regex;
I have a pathname like some-component and I need to generate an output like SomeComponent using vscode snippet.
I need to input sendData and return an string like const sendData = createMessage(SEND_DATA);
How can I do this using regex on vscode snippet?
"${TM_DIRECTORY/(.*)/${1:/pascalcase}/g}" you didn't really provide enough info on how you are getting your pathName, so this is just one possibility, perhaps RELATIVE_FILEPATH` works for you.
"$1 = createMessage(${1/(([^A-Z]+)(\\w*))/${2:/upcase}_${3:/upcase}/});"
split the input sendData into 2 capture groups $2 and $3. Upcase them both in the transform.
"sendData": {
"prefix": "cm",
"body": [
"${TM_DIRECTORY/(.*)/${1:/pascalcase}/}",
// simpler form if ONLY two "words" like "sendData"
"$1 = createMessage(${1/(([^A-Z]+)(\\w*))/${2:/upcase}_${3:/upcase}/});",
// for any number of words, like "sendDataTwoThreeFour" use this:
"$1 = createMessage(${1/([a-z]*)([A-Z][a-z]*)/${1:/upcase}${2:+_}${2:/upcase}/g});"
]
}
${1/([a-z]*)([A-Z][a-z]*)/${1:/upcase}${2:+_}${2:/upcase}/g} get the first word "send" into capture group 1 and the other words like "Data" or "Two", etc. into subsequent matches' capture group 2. [So the g flag at the end is very important.]
Upcase group1. Then if there is a group 2 ${2:+_} add _. Then upcase group2.
The only case this will not work on is send with nothing else. It still prints out the all the text just doesn't upcase send if it is by itself. There is probably a way to include that...
Edit: And here it is:
"$1 = createMessage(${1/([a-z]*)([A-Z][a-z]*)|([a-z]+)/${1:/upcase}${3:/upcase}${2:+_}${2:/upcase}/g});"
now a bare send will be put into group 3 and upcased. For the rest of the matches there will not be a group 3 so ${3:/upcase} returns nothing.

Snippet for title in restructured text in vs code

In restructured text, titles are written with equal number of nonalphanumeric 7-bit ASCII
character as the title text. The underline and overline if both used, should be equal and at least as long as title text. From the official docs:
Titles are underlined (or over-
and underlined) with a printing
nonalphanumeric 7-bit ASCII
character. Recommended choices
are "= - ` : ' " ~ ^ _ * + # < >".
The underline/overline must be at
least as long as the title text.
Example of a title
=========================================================
Main titles are written using equals signs over and under
=========================================================
I want to create a VS Code snippet for this. What I could do was only this,
"Title RST": {
"prefix": "title",
"body": [
"="
"$1"
"=\n"
"$0"
],
"description": "Title for restructured text"
}
Is there a way to know the length of the text that will be typed, and correspondingly insert same number of overline and underline =.
In yasnippet in emacs, they do it as:
${1:$(make-string (string-width yas-text) ?\=)}
${1:Title}
${1:$(make-string (string-width yas-text) ?\=)}
$0
Any help how to implement such snippet in VS code? I looked under snippets in restructured text extension for VS Code here but could not find that suits my needs.
"Title RST": {
"prefix": "title",
"body": [
"${1/./=/g}",
"$1",
"${1/./=/g}",
"$0"
],
"description": "Title for restructured text"
},
The transforms ${1/./=/g} just replace every character in your text $1 with a = in the line above and below your text.
You need commas at the end of your snippet entries and there is no need for the newline as another line in the snippet body is already a newline.
When you type your text hit Tab and the transform will be completed.
You asked if was possible to get the over/underlines to show as =s immediately upon typing your title text. But that isn't possible with vscode snippets, a transform is required and that won't happen until the Tab.
It can be done with HyperSnips version (a little more trouble to set up than plain vscode snippets, but not much):
snippet title "Title" A
``rv = '='.repeat(t[0].length)``
$1
``rv = '='.repeat(t[0].length)``
endsnippet

Word mail merge errors in "by category"

Please see the attachments for the mail merge issue. The result expected by me should have been:
But it turns out to be:
I believe the error is caused by the comparison in the field codes (i.e. <>) but I couldn't figure out where the error is. If I make a change to the data,
1A --> F1A
OR
1A --> A1
The error disappears. Here are the field codes:
Thanks for any help in advance!
You need to put double quotation marks around { Place2 } and { Place1 }, e.g.
"{ Place2 }"
As it is, when word does the comparison, it will evaluate values such as 1A, 2D etc. as the numbers 1 , 2 etc. Since your list starts with 1A, 1C, the comparison will be { IF 1 <> 1 } so the transition from 1A to 1C will be missed.
If you want to ensure that Word does a textual comparison, this is one reason. In fact in this scenario Word treats things that look like simple arithmetic expressions as such so if Place1 was called "2*4" and Place2 was called "8", you would get a match if you did not include the quotation marks.
There are other reasons why it is advisable to quote the comparands in an IF field when you want them to be treated as text. For example if you have the following, X is definitely "abc" and Y is definitely "def" .
{ SET X "abc" }{ SET abc "def" }{ SET Y "def" }{ X }{ Y }
But this will return "equal"
{ IF { X } = { Y } "equal" "not equal" }
whereas this will return "not equal"
{ IF "{ X }" = "{ Y }" "equal" "not equal" }
In other words, if a comparand is not quoted and evaluates to the name of a bookmark in the document, it is treated as a reference to the bookmark value and is dereferenced.

Table of Contents nested fields lose the hyperlink at page numbers

I wrote a nested field for Microsoft Word (Windows, Office 2010) Table of Contents which allows me to change the error text when no Figures entries (Caption style with the word "Figure" in the string) exist.
I don't know how to represent the Field marks, so I'm using "FS" and "FE" to indicate the field brackets.
FS IF FS TOC \c"Figure" FE = "<carriagereturn>No table of figures entries found." "No figures at this time" FS TOC \c"Figure" FE FE
This works so far as displaying either my error message or the table of figures, but the usual hyperlinking for the page numbers (Control-Click to jump) is not available. I'm guessing it has something to do with the nested fields, but can't figure out if there's a workaround.
If there's a better way, using fields, to do this, I"m happy to change over.
EDIT: I don't suppose it's possible to edit the error string itself inside the wordcnvr.dll file?
How about this instead:
{ IF "{ TOC \c "Figure" }" = "
No table*" "{ SET ToCFormat Charformat }Then the error message you want to display." "{ SET TocFormat Mergeformat }" }
{ TOC \c "Figure" \*{ ToCFormat } }
and format the font of the "T" of the second TOC to be coloured white and be 1pt size (or smaller, if possible). NB, formatting the "T" as Hidden won't work, as Word will treat the field code as if it starts with "OC".
I wasn't able to find any significant improvements to this from the layout point of view, but if anyone is likely to open/update your document on a non-English langugae version of Word you should probably use
{ IF "{ TOC \c "Figure" }" = "{ TOC \c "Nolist" }" (etc...) }
where Nolist is known to have no associated SEQ fields. You'll get an extra prompt, though.
Also, if anyone is likely to open/update your document on Mac Word (2011, anyway), that version actually generates a multiline error message with advice (whereas Windows Word puts the advice in a message box). The result still only occupies a few points of vertical space but you could generate a TOC for something that only has one entry instead. Overall, I think you would end up with something like
{ IF "{ TOC \c "Figure" }" = "{ TOC \c "Nolist" }" "{ SET ToCFormat Charformat }{ SET theList OneEntry }Your error message" "{ SET ToCFormat Mergeformat }{ SET theList Figure }" }{ SEQ OneEntry \#"' '" }{ TOC \c { theList } \* { ToCFormat } }
formatting the "T" as before and fixing whatever you had to fix with the * switch.
Finally, from an international perspective, using "‘ ‘", with two left single quotation marks (U+2018), is a better choice than "' '", but only to deal with Switzerland's regional settings, and it may not work with older versions of Word.

How to mirror statements in Notepad++

I have a file with hundreds of these kind of statements:
If Description = "Approach light" Then Obstakelcode = "AL"
If Description = "Common mast" Then Obstakelcode = "CoM"
etc.
With a Notepad++ macro I tried to 'mirror' these statements in:
If Obstakelcode = "AL" Then Description = "Approach light"
If Obstakelcode = "CoM" Then Description = "Common mast"
etc.
However, I failed. Can anybody tell me if this can be done easily with Notepad++?
On the Notepad++ Find/Replace screen, with Regular expression selected, please type
Find what
If\s(Description\s+=\s+\"[^\"]+\")\s+Then\s(Obstakelcode\s=\s\"[^\"]+\")
Replace with
If \2 Then \1
The expression between If and Then is captured as group \1 and the expression between Then up to the closing " is captured as \2. The Replace command mirrors it according to your requirement.