Nice idea for a script and it has potential
... but...
quote:
Originally posted by Matti
Validation of numbers (for example, it will allow "text" as a valid height measurement)
js code:
var sFoo = "85.1";
var nFoo = 1 * sFoo; //Attempt a string to number conversion
if( isNaN(nFoo) ) nFoo = 0; //Failed, set to some default value or ignore the declaration
You don't need to multiply it with 1.
The next code will work just as good because the function isNaN() will already attempt to convert the variable to a number:
js code:
var sFoo = "85.1";
if( isNaN(sFoo) ) nFoo = 0
In any case, whiz, check your code more carefully so you don't forget crucial stuff or make small mistakes. Although it wouldn't result in a wrong check (because of the above), you forgot to multiply the "EdtHeight" with 1 when you implemented the code posted by Matti:
code:
if (isNaN(objWnd.GetControlText("EdtWidth") * 1) == true || isNaN(objWnd.GetControlText("EdtHeight") * 1) == true)
So in this case you are lucky that you didn't needed the *1 at all, but in other cases such mistakes might result in hard to find bugs...
So, the above line can be written as:
code:
if (isNaN(objWnd.GetControlText("EdtWidth")) || isNaN(objWnd.GetControlText("EdtHeight")))
Also:
Remember to take the casing of strings into consideration when you compare strings. Code like:
js code:
for( var i in WndLstId ) {
>>> if( WndLstId[i] == sTestId ) {<<<
bIsUniqueId = false;
break;
}
}
...will fail if the Id of one control is "Btn
Test" and the other control "Btn
test".
You must convert the strings to the same casing (eg: lowercase) when comparing.
Even if the control id is case sensitive and using "Btn
Test" for one control and "Btn
test" for another is allowed, it is still a good idea to still dissallow it in your script because it is not recommended and not good practice and as a result such things _will_ eventually result in errors in the used scripts. So:
js code:
if( WndLstId[i][b].toLowerCase() === sTestId.toLowerCase() ) {
PS: also notice the use of === (is identical) instead of == (is equal). Learn more about the difference
here.
----
The above are all small details but can make a very big difference. So, a very big tip: before adding new stuff and/or features, revise your entire script very carefully as it contains many (small but crucial) errors and potential bugs, like vaccination already said.