Round A Variable Autohotkey - variables

I've been trying to round a variable for the past hour and cannot figure out how to do so.
average_load = 1.234
average_load := Round(%average_load%)
It keeps saying that it contains an illegal character.

Functions are always expression capable and thus variables do not need to be quoted.
average_load = 1.234
average_load := Round(average_load)
What is expression capable? See examples of Variables and Expressions.
It is same difference as := is expression ready so variables do not need to be declared whereas for = the expressions must be declared with surrounding % or a leading %.

Related

What does $$ mean when using DO, CREATE FUNCTION, etc? [duplicate]

This question already has answers here:
What are '$$' used for in PL/pgSQL
(2 answers)
Closed 3 years ago.
I have seen the double dollar sign ($$) being used often in FUNCTION declarations and while doing declare statements. I acknowledge that it is probably some syntax related feature, but I am not too clear how/why to use it and when.
Code examples of usage below:
CREATE OR REPLACE FUNCTION BuildFunction(IN prefix TEXT, IN func_id INTEGER) RETURNS BOOLEAN AS $$
BEGIN
...
END; $$
Point of confusion, how do you return a boolean as a $$, is it some special type or something?
DO $$
DECLARE
a integer := 10;
b integer := 20;
c integer;
BEGIN
c := a + b;
RAISE NOTICE'Value of c: %', c;
END $$;
This code snippet is from How do you use variables in a simple PostgreSQL script?
From the fine manual:
4.1.2.4. Dollar-Quoted String Constants
While the standard syntax for specifying string constants is usually convenient, it can be difficult to understand when the desired string contains many single quotes or backslashes, since each of those must be doubled. To allow more readable queries in such situations, PostgreSQL provides another way, called “dollar quoting”, to write string constants. A dollar-quoted string constant consists of a dollar sign ($), an optional “tag” of zero or more characters, another dollar sign, an arbitrary sequence of characters that makes up the string content, a dollar sign, the same tag that began this dollar quote, and a dollar sign.
The dollar quoting is a PostgreSQL-specific way of quoting strings that will contain a lot of internal single quotes without forcing you to escape quotes and make an unreadable mess. So these are equivalent string literals:
'R''hllor'
$$R'hllor$$
Dollar-quoting isn't specific to functions, you can use it for any string literals, but it is most commonly seen in function definitions as in your two examples.

Use variable in GAMS dollar

I have a GAMS code where I want an if statement. I've read about dollar condition and I thought it could help me. Reading GAMS user guide, it says:
The Dollar Condition
This section introduces the dollar operator , which is one of the most powerful features of GAMS. The dollar operator operates with a logical condition. The term $(condition) can be read as 'such that condition is valid' where condition is a logical condition.
Attention:
The dollar logical conditions cannot contain variables. Variable attributes (like .l and .m) are permitted however.
The dollar operator is used to model conditional assignments, expressions, and equations. The following subsection provides an example that will clarify its use. The next section will deal individually with the topic of using dollar conditions to model conditional assignments, expressions, and equations respectively.
I have tryed it in my code, but still I found always the same error:
*** Error 53 in C:\route\Filename.gms
Endogenous $ operation not allowed
This is my actual code:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA(k,l,t) GE GT(k,l)) =E= 0 ;
(I want to change value of a variable to 0 if it is greater or equal to another variable). I have also tryed with .l attribute:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA(k,l,t).l GE GT(k,l).l) =E= 0 ;
but then next error appears (just in the .l definition)
*** Error 8 in C:\route\Filename.gms
')' expected
Please, could anyone help?
Thanks in advance!!
I have seen that my previous code was not correct, the correct way is:
ACUMULADO_FIN_GRUPOS(k,l,t)..
GA(k,l,t)$(GA.l(k,l,t) GE GT.l(k,l)) =E= 0 ;
with the .l previous to set definition.

What is significance of trailing "$" in some function names?

I recently looked at some vba source at Microsoft: [Convert Fractions to Decimal Values][1]
[1]: https://support.microsoft.com/en-us/kb/185424 and I noticed that several functions had a trailing "$", specifically trim$(), left$(), and mid$(). My question is: what does the "$" signify?
I downloaded the microsoft function and it ran correctly under Excel 2007.
Since VBA trim() works differently from the worksheet function trim(), I wrote a small program to compare the operation of the 3 possible trim() calls. I found that trim() and trim$() produced identical output. worksheetfunction.trim(), of course, produces output that has extraneous space characters removed from inside the string.
I am very curious about the trailing "$", and will be grateful for enlightenment!
Thank you,
Dave
To quote from https://bytes.com/topic/access/answers/196893-difference-between-left-left-function
Allen Browne
The trailing $ is a type declaration character for the String data type in
VBA.
The result returned from Left$() is a string, whereas Left() returns a
Variant.
You must use Left(), not Left$() if there is any chance of Null values,
since the Variant can be Null but the String cannot.
That post has a full worked example
The syntax is a left-over habit from ancient history. In early versions of Basic variables did not have to be declared but data types were implied by the name of the variable. Any variable ending with $ was a string and any variable ending with % was an integer.
FORTRAN had a similar convention: any variable starting with the letters I, J, K, L, M or N were integers, all others were real.

Regular expression to match specific variations of function

I am trying to construct a regular expression to find the text of the following variations.
NSLocalizedString(#"TEXT")
NSLocalizedStringFromTable(#"TEXT")
NSLocalizedStringWithDefaultValue(#"TEXT")
...
The goal is to extract TEXT. I have been able to construct a regex for each individual function or macro, e.g., (?<=NSLocalizedString)\(#"(.*?)". However, I am looking for a solution that does the job no matter what the name of the function as long as it starts with NSLocalizedString.
I assumed it was as simple as (?<=NSLocalizedString\w+)\(#"(.*?)", but that does't seem to do the trick.
How about this one?
/NSLocalizedString\w*\(#"(.*)"\)/
Explanation:
NSLocalizedString 'NSLocalizedString'
\w+ word characters (a-z, A-Z, 0-9, _) (0 or
more times (matching the most amount
possible))
\( '('
#" '#"'
( group and capture to \1:
.* any character except \n (0 or more times
(matching the most amount possible))
) end of \1
" '"'
\) ')'
The only reason your regex doesn't work is because the regex engine doesn't support variable length lookbehinds. The (?<=NSLocalizedString\w+) is variable length so can't be used.
Firstly it needs to be \w* not \w+, to allow your first example string to match.
If you move the \w* outside the lookbehind (?<=NSLocalizedString)\w* it will work just fine.
Alternatively, since you have to use a capturing group to grab the text value anyway, theres no need for the lookbehind at all. Change the (?<= to a (?: and it becomes a non-capturing group (which can be variable length), and then just grab your text value from group 1.
Your attempt was:
(?<=NSLocalizedString\w+)\(#"(.*?)"
Both of these minor changes should make it work:
(?<=NSLocalizedString)\w*\(#"(.*?)"
(?:NSLocalizedString\w*)\(#"(.*?)"
The following is actually not supported in Objective-C:
The solution that will extract exactly TEXT without using any groups is:
NSLocalizedString\w*\(#"\K[^"]*
It avoids the need to use a negative lookbehind (which can't be used for reasons I explain below) by using the \K modifier, which chops off anything before it from the match.

Exclamation(!) operator used on a number in vb.net, what does this do?

I'm looking at inherited code and I found this in a vb.net windows form:
New System.Drawing.SizeF(6.0!, 13.0!)
My question is, what is the significance of the ! (exclamation) operator here? Most of my searching for the exclamation operator ends up returning recordset format or the ! gets ignored in the search and I get hundreds of unrelated items.
It's to force the literal to be a Single.
Visual Basic supports Type Characters:
In addition to specifying a data type in a declaration statement, you can force the data type of some programming elements with a type character. The type character must immediately follow the element, with no intervening characters of any kind.
and:
Literals can also use the identifier type characters (%, &, #, !, #, $), as can variables, constants, and expressions. However, the literal type characters (S, I, L, D, F, R, C) can be used only with literals.
In this case, the ! stands for Single:
Type Characters. Appending the literal type character F to a literal forces it to the Single data type. Appending the identifier type character ! to any identifier forces it to Single.
(emphasis mine)
It is a type character. It means that 6.0 is a Single data type.
http://msdn.microsoft.com/en-us/library/s9cz43ek.aspx show the type characters.