VB Script if statement: Sub not defined - if-statement

I have the code below
if (LCase(Config_(C_))) like "show*" Then
crt.screen.send Config_(C_) & VBCR
crt.screen.WaitForStrings ">", "#"
End If
but when I run it I get a "Sub not defined on line 36 (which is the "if(LCase(....." line)
Config_ is an array of strings
C_ is the element address
So all I want to do is say,
If this array element starts with "show" then run the command, insuring it does not matter if the user emters upper or lower case.
Why this code does not work? Other if like statements seem ok.

As far as I'm aware, there's no like statement in vbscript. You could use Left which will return n number of characters at the start of a string and see if the string it return equals "show" -
if Left(LCase(Config_(C_)),4) = "show" Then

The work "LIKE" is not a key word or a function in vbscript

Related

Tcl - How to Add Text after last character through regex?

I need a tip, tip or suggestion followed by some example of how I can add an extension in .txt format after the last character of a variable's output line.
For example:
set txt " ONLINE ENGLISH COURSE - LESSON 5 "
set result [concat "$txt" .txt]
Print:
Note that there is space in the start, means and fin of the variable phrase (txt). What must be maintained are the spaces of the start and means. But replace the last space after the end of the sentence, with the format of the extension [.txt].
With the built-in concat method of Tcl, it does not achieve the desired effect.
The expected result was something like this:
ONLINE ENGLISH COURSE - LESSON 5.txt
I know I could remove spaces with string map but I don't know how to remove just the last occurrence on the line.
And otherwise I don’t know how to remove the last space to add the text [.txt]
If anyone can point me to one or more solutions, thank you in advance.
set result "[string trimright $txt].txt"
or
set result [regsub {\s*$} $txt ".txt"]

T32 script usage

Can anyone help me on this script?
What did the function do?
Thanks!
========================================================
&AAA=0
if (string.scan(string.lwr("&parameters"),"AAA",0)!=-1)
(
&AAA=1
)
========================================================
Well I guess your code looks like this:
&AAA=0
if (string.scan(string.lwr("&parameters"),"AAA",0)!=-1)
(
&AAA=1
)
Note: The round brackets for opening and closing a block in a PRACTICE script must be placed in separate lines.
About the meaning: Your script has two "variables" (aka. "macro"): &parameters and &AAA.
In the first line you initialize &AAA with 0.
In the second line you use string.lwr() to get the content of the variable &parameters converted to lower-case.
Then you search in this lower-case string for a string "AAA" (which is ironically upper case) beginning from the first letter (with string.scan()).
The result of string.scan() is -1 if the string "AAA" wasn't part of the lower-case version of &parameters
So variable &AAA gets set to 1, if a lower-case version of &parameters contain the string "AAA" (which is never the case since "AAA" is upper-case).
Maybe the writer of the script wanted to use string.upr() instead of string.lwr().

Create an If statement comparing a custom field MS Word

I'm trying to create an if statement (in MS Word) that looks at a custom field.
The custom field is DocProperty Client_ABV
I want it to print a line of text if client_abv matches a certain value else be completely blank (or delete the empty line if possible)
I believe it needs to look something like this:
{IF DocProperty.Client_ABV="Test" "Print this line if Test",""}
I've very little experience with this function in Word but I have some with conditional programming.
Can anyone shed any light. I've been googling it for the last 45 minutes and have had little success with the example pages I've found.
Use Ctrl+F9 to insert the field code { brackets }. They look like wavy brackets, but these are actually special "escape codes" that tell Word this is a field code.
You need a pair of brackets for both the IF and the DocProperty fields.
When performing a string comparison it's a good idea to put "quotes" around the field code as well as around the literal string.
There is no punctuation in the DocProperty field code (no period). And no comma between the true/false evaluation, only a space between the closing " and opening ".
If a paragraph mark should be part of the true/false evaluation (for example, you want to suppress the paragraph mark if the comparison is false) include it inside the "quotes" for the evaluation result. The field code will look a bit odd, but that does work.
For example:
{ IF "{ DocProperty Client_ABV }"="Test" "Print this line if Test¶
" ""}

Google sheets custom function w/ regex fails on alternating rows when used in range

I just wrote up a simple google sheets function to fix some URLs. This function works fine in a browser, when passed the array of values manually. When called from google sheets, the function fails for every other row.
This isn't a problem with data, since I can make it work for the "failing" rows by moving the formula down one row, or calling it individually for each cell. I think this may be an issue with regex inside google sheets.
var pattern = /^http:\/\/(.*\/\d\/.*)_(.*)\/(g\d+p.*)$/ig;
function encode(input) {
if (!input) return "";
if (input.map) {
return input.map(encode);
} else {
try {
// same error happens, at this location, w/ or w/o toString()
var matches = pattern.exec(input.toString());
return matches[1] + encodeURIComponent(matches[2]) + matches[3];
} catch (e) {
return "error=" + e.message + " value = [" + input + "] ";
}
}
}
Edit: To make things clearer for those who come after, this also fails the same way when the regex is inside the "else" clause:
else {
var matches = /^(http:\/\/.*\/\d\/.*_)(.*)(\/g\d+p.*)$/ig.exec(input.toString());
... continues as normal
For alternating rows of the data, I get this error message:
error=Cannot read property "1" from null. value = [ http://... ]
I have tried:
Putting the regex inside the try{}
Putting the regex inside the encode{} function
Writing two separate functions (one for doing 1 value)
In the failure case I have data like this:
A1-A8 have URLs in them
B1 has the formula "=encode(A1:A8)"
Data in B1, B3, B5, B7 calculate perfectly
Data in B2, B4, B6, B8 error out (my error message shows up)
Moving the formula to cell "B2" and saying =encode(A2:A8) causes all the "failing" rows to calculate and the others to fail!
The short answer (as confirmed by your comment on the OP) is to remove the final "g" (the global flag) from the regex.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec
Syntax regexObj.exec(str)
Parameters str The string against which to match the regular expression.
...
If your regular expression uses the "g" flag, you can use the exec()
method multiple times to find successive matches in the same string.
When you do so, the search starts at the substring of str specified by
the regular expression's lastIndex property (test() will also advance
the lastIndex property).
So it seems you really should only include the global flag when you intend to continue to search for matches in the same string.
As to why it worked in other environments, I'm not sure. Indeed, it seems a bit strange to continue searching from where you left off, even though you are applying exec to an entirely new string. Perhaps the implementation in GAS is a little bit "off" - someone with more knowledge might be able to comment on this.
To elaborate on my comment, the error means that matches is empty or non-existent, which probably means that the regex did not find a match. So it is important to see whether the value of input should match or indeed does not conform to the requirements of the regex.
The regex does the following:
^http:\/\/(.*\/\d\/.*)_(.*)\/(g\d+p.*)$
Debuggex Demo, Matched text:
http://whatever/3/some_thing/g4p/can be anything
^^^^^^^ ^^^ ^ ^^^^
So if any of the following is not found in the URL, no match will be returned:
URL does not start with http:// (but, for instance, https://)
There is no occurrence of: /, a number, /
There is no _
There is no occurrence of /g, some numbers, p
Are you sure the text meets all these requirements every time?

regex and file read line in autohotley

well i am currently writing a script that is meant to check the logs of another script i wrote to see if it has had three or more unsuccessful pings in a row before a successful one, this is just barebones at the moment but it should look something like this
fileread,x,C:\Users\Michael\Desktop\ping.txt
result:=RegExMatch(%x% ,failure success)
msgbox,,, The file is = %x% `n the result is = %result%
now the file that is trying to read is
success failure success
and for some reason, when it reads the file it says that the variable %x% 'contains illegal characters
when i copy and paste the contents of ping.txt into the script and save it as a variable it works
i have made sure that the file has windows line endings CR +LF
i have assigned the variable generated in file read as another variable thus stripping any trailing or leading whitespace characters
the file is encoded in ANSI and still has the problem with UTF8
Function parameters take variable names without the % symbol, simply remove them.
I also want to point out that if the second parameter is meant to be a regular expression,
instead of a variable containing a regular expression, you will need quotes around it.
As is your script passes an empty string as the pattern which will always return 1
(failure is interpreted as a variable with an empty string associated with it.).
To quote Lexikos:
"An empty string, when compiled as a regex pattern, will match exactly
zero characters at whatever position you attempt to match it. Think of
it this way: For any position n in any string, the next 0 characters
are always the same."
Because you are simply truth testing,
or finding the index I want to point out that Autohotkey has a useful shorthand operator for this.
string := "this is a test"
f1::
result := RegExMatch(string, "\sis")
traytip,, %result%
Return
f2::
result := string ~= "\sis"
traytip,, % result
Return
These hotkeys both do the same thing; the second uses the shorthand operator ~=
and notice how the traytip parameter in the second example has only one %
When you start a command parameter with a % that starts an expression,
and within an expression variables are not enclosed with %.
The ternary operator ?: is also very useful:
string := "this is a test"
f3::traytip,, % (result := string ~= "\sis") ? (result) : ("nothing")
It might look complicated but it's very simple.
Think of
% as if
? as then
: as else
If (true) then (a) else (b)
% (true) ? (a) : (b)
A variable will be evaluated as False if 0 (or nothing) is assigned to it.
But in this example "\sis" is matched and the index of the space is returned (5),
so it is evaluated as True.
You can read more about variables and operators here:
http://l.autohotkey.net/docs/Variables.htm