Autoit Why is (0 <> "Test") False - autoit

I am fetching a numeric value from an HTML table. If it fails to fetch the value I fill the value "NA" instead. Here is the odd part 0 <> "NA" is false, 0 = "NA" is true, 0 == "NA" is False. I get that = is not case sensitive, and == is, but I thought <> was case sensitive... So why does it work like this?
Local $x = 0
If $x <> "Test" Then
MsgBox(0,"","x <> Test")
Else
MsgBox(0,"","x = Test")
EndIf
With this exaplle I get a message box "x = Test"

but I thought <> was case sensitive
According to the docs, it is not a string-specific comparison operator like ==. Rather, it’s just the negation of =, so your string will still be interpreted as an integer – both "NA" and "Test" becoming 0 – and fail to satisfy 0 <> 0.
Tests if two values are not equal. Case insensitive when used with strings. To do a case sensitive not equal comparison use Not ("string1" == "string2")

Related

PROGRESS 4GL - does IF condition supports for dimensional array?

I am new to progress 4GL language. I have written a logic which is trying to check <> "" values for dimensional arrays and giving syntax error. Can anyone pls help me where I am making mistakes and the logic I written is correct or not?
DEFINE VARIABLE anotarray AS CHARACTER NO-UNDO.
DEFINE VARIABLE barray AS CHARACTER EXTENT 3 NO-UNDO.
ASSIGN
barray[1] = "yes"
barray[2] = "no"
anotarray = ""
.
/***value can be stored randomly in variable barray. so we cannot specify [1],[2],[3] for if condition***/
/***based on req. I need to check both anotarray or barray <> "" ***/
IF (anotarray OR barray ) <> "" THEN DISP barray.
/*** ERROR thrown- An array was specified in an expression, on the right-hand side of an assignment, or as a parameter when no array is appropriate or expected. (361)*** /
This syntax is not valid : IF (anotarray OR barray) <> "" THEN ...
You have to cycle through all elements of your array. You can do it using a DO statement and the EXTENT function.
Also, you have to compare both variables to the empty string : IF anotarray <> "" OR barray[ix] <> "" THEN ...
This code should work :
DEFINE VARIABLE anotarray AS CHARACTER NO-UNDO.
DEFINE VARIABLE barray AS CHARACTER EXTENT 3 NO-UNDO.
DEFINE VARIABLE ix AS INTEGER NO-UNDO.
ASSIGN
barray[1] = "yes"
barray[2] = "no"
anotarray = ""
.
DO ix = 1 TO EXTENT(barray):
IF barray[ix] <> "" OR anotarray <> "" THEN DISP barray[ix].
END.
You have two problems in this expression:
anotarray or barray
One is the error 361 that you have reported. That error is because you cannot check the entire array all at once. You need to check each element of the array.
The other issue is that OR compares logical values not character values.
So what you probably want to write is something more like:
if ( anotearry <> "" or barray[1] <> "" or barray[2] ) then display barray.

Netsuite - Saved Search Formula(text) Case statement multiply 2 fields

I'm trying to get the product of 2 fields in the 'ELSE' portion of a CASE statement of a Formula(Text) row in a Netsuite saved search, but I keep getting 'ERROR: Invalid Expression' when I run the search. Current formula is:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
I've tried to simplify it by doing something like this:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE 1 + 1 END
But it still fails with an invalid expression error. All of the Googling I've done leads me to believe that this should work, but I can't seem to find my mistake. I'm hoping the extra eyes here can give me a kick in the right direction. Thank you.
The data type returned from the formula needs to match the Formula type selected. You can correct your formula by setting it to a Formula (Numeric) type and simply removing the quotes around the '0' after the first THEN:
CASE WHEN {binonhandcount} = 0 THEN 0 ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
Or if you really want a text formula for some reason, you can wrap the ELSE statement in a TO_CHAR function:
CASE WHEN {binonhandcount} = 0 THEN '0' ELSE TO_CHAR(NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0)) END
In your NetSuite saved search replace Formula(text) to Formula(Numeric).
And your formula would be:
CASE WHEN {binonhandcount} = 0 THEN 0 ELSE NVL({binonhandcount}, 0) * NVL({locationaveragecost}, 0) END
Please remove the string from THEN '0'. You should be fine.

Comparitive operator not working in Julia script file when used in control flow with conditional operator

I have tried different operators <,>,etc. Nothing seems to work when I combine comparative operators with conditional operators.
e = readline()
if e == 0
println("e is equal to 0")
else
println("e is not equal to 0")
end
The expected result is obvious, if e = 0, prints e is equal to 0, if e != 0, prints e is not equal to 0.
However, it always prints the bottom line, e is not equal to 0.
That's because readline returns a string, which is never equal to an integer (by the definition of == Julia uses).
Here are some possible ways to achieve what you want:
Compare to a string literal instead: if e == "0"
Use tryparse: if tryparse(Int, e) == 0 (will return nothing if e is not a number literal)
Use parse, but with try/catch instead of an if:
try
p = parse(Int, e)
p == 0 ? println("e is 0") : println("e is not 0")
catch
println("not even an integer.")
end
The reason that the if returns the branch that you don't expect is those given to you by #phg (you got a String by readline()).
For my code I use the following function to parse user-provided data given in a terminal:
function getUserInput(T=String,msg="")
print("$msg ")
if T == String
return readline()
else
try
return parse(T,readline())
catch
println("Sorry, I could not interpret your answer. Please try again")
getUserInput(T,msg)
end
end
end
sentence = getUserInput(String,"Which sentence do you want to be repeated?");
n = getUserInput(Int64,"How many times do you want it to be repeated?");
[println(sentence) for i in 1:n]
println("Done!")

Vb script string comparison error

I have tried all but its not working
I am getting a colum value form Data base as
substatus=rsprefobj("isnotificationactive");
after doing
Response.write substatus
It gives me --> n
and when i do
intcomaprestringval=StrComp(substatus,"n",vbTextCompare)
Response.write intcomaprestringval
It(intcomaprestringval) gives me --> 1 even though they are same
I want to take some decision based on database value if its "n" or "y"
If intcomaprestringval = 0 Then
some
Else
some
End If
But StrComp()always returns 1 in my case whether database value is "n" or "y" :(
I write a compare function that will return either "OK" if 2 values are a match or "No Match" if they do not. Here it is:
Function Compare(str1, str2, comp)
str = "OK"
If StrComp(str1, str2, comp) <> 0 Then str = "No Match"
Compare = str
End Function
str1 and str2 are the 2 values you wish to compare and comp is the method of comparison (0 = binary comparison and 1 = text comparison). I always use 0.
So you would use it like this:
If Compare(substatus, "n", 0) = "OK" Then
' Values match
Else
'Values do not match
End If
Hope it helps
Regarding your test:
intcomaprestringval=StrComp(substatus,"n",vbTextCompare)
Are you setting vbTextCompare to be 0 at some point earlier in your code?
I have used Trim() as suggested by #EntBark
Dim myvalue
myvalue=Trim(substatus)
intcomaprestringval=StrComp(myvalue,"n",vbTextCompare)

Check if palindrome while ignoring special characters

I'm failing the last test case, which is the one with the spaces and single quotation mark.
I used s.strip, but the error still persists.
Is there another way to go about this?
Thank you.
from test import testEqual
def removeWhite(s):
s.strip()
s.strip("'")
return s
def isPal(s):
if s == "" or len(s) == 1:
return True
if removeWhite(s[0]) != removeWhite(s[-1]):
return False
return isPal(removeWhite(s[1:-1]))
testEqual(isPal(removeWhite("x")),True)
testEqual(isPal(removeWhite("radar")),True)
testEqual(isPal(removeWhite("hello")),False)
testEqual(isPal(removeWhite("")),True)
testEqual(isPal(removeWhite("hannah")),True)
testEqual(isPal(removeWhite("madam i'm adam")),True)
At first your removeWhite function doesn't return all spaces because strip only removes from the end and the beginning of a string. See:
>>> " a ".strip()
'a'
>>> " a a ".strip()
'a a'
So i suggest this approach:
def removeWhite(s):
return ''.join(filter(lambda x: x not in " '", s))
Please note that I use join because filter returns an iterator which needs to be converted back to a string.
For finding the palindromes i would suggest this function:
def isPal(s):
if len(s) <= 1: # Special case to prevent KeyError later
return True
stripped = removeWhite(s) # Strip off all whitespaces
first = stripped[:len(stripped) // 2] # First half of the string
if len(stripped) % 2: # Length of string is even?
second = stripped[len(stripped) // 2 + 1:] # Drop the middle character
else:
second = stripped[len(stripped) // 2:] # Else keep it
secondrev = ''.join(reversed(second)) # Reverse the second half
return first == secondrev # And return wether they're equal.
This holds for all your examples. But it think your isPal function should work too if you fix your removeWhite function

Resources