How can I solve this error: "Cannot use true operator for a text value"? - automation

So, I´m using winautomation v5 to create a bot that does as follows:
Executes a query to get a table from a database and saves the info in a %table% variable.
I have a for each loop that iterates %table% and saves the current row in the %factura% variable.
A function that assigns each factura´s field to a variable: %NIS% = %factura[0]% , %Proceso% = %factura[1]% , ..... = %factura[2]%, ..... = %factura[3]%, etc.
On each iteration, I have a couple of nested if, else if, else where I have the error.
If the NIS variable is empty, set variable as "NULL"
Nested if´s
Error
In the first IF, I have tried to set it as:
- First Operand: %NIS != "NULL" && NIS != ""% Operator: = Second Operand: True
- First Operand: %NIS% != "NULL" && %NIS% != "" Operator:=Second Operand: True
- First Operand: %NIS <> "NULL"% && %NIS <> ""% Operator:= Second Operand: True
- First Operand: % (NIS != "") && (NIS != "NULL") % Operator: = Second Operand: True
- First Operand: (%NIS% != "") && (%NIS% != "NULL") Operator:= Second Operand: True
But I keep getting the same Cannot use operator true for a text value

Related

If Else Statement in vb.Net

I wanted to have this condition like i have b2.text, c3.text, d4.text, e5.text, f6.text, g7.text, h8.text, i9.text and j10.text.
And if they are all equal to zero then statement else continue.
i tried
If (b2.Text = 0 & c3.Text = 0 & d4.Text = 0 & e5.Text = 0 & f6.Text = 0 & g7.Text = 0 & h8.Text = 0 & i9.Text = 0 & j10.Text = 0) Then
a1.Text = 10000000
Else
Msgbox.Show("Cannot sort")
End if
Unfortunately i remembered & function only accept two variable only :P
How can i do it?
Thank you
You don't want & for VB, you want AndAlso. And while it is probably a bit above your level, you might want to look into Linq.
If ({b2.Text, c3.Text, d4.Text, e5.Text, f6.Text, g7.Text, h8.Text, i9.Text, j10.Text}).All(Function(f) f = "0") Then
a1.Text = 10000000
Else
Msgbox.Show("Cannot sort")
End IF
As others have said, you should turn on Option Strict, so that your comparison to an int gets flagged. I made the string "0" above, but you could easily modify it to use length if that is what you actually need.
I don't know what language are you using but I'm pretty sure you can compare more than 2 values The solution may be like this.
if (b2.text == 0 && c3.text == 0 && d4.text == 0 && e5.text== 0 && f6.text == 0 && g7.text == 0 && h8.text == 0 && i9.text == 0 && j10.text == 0) {
// when conditions are true
}
else {
// else code here
}

Return True if specific value exists in table - sql

I want to create an SQL query that will return True if a specific value exists in a specific column; if not, then it will return False.
I know that I can create something like 'SELECT something FROM somewhere WHERE something'. In this case I don't want to select anything, just to check.
My question is how can I do it.
You can use the IIf function:
SELECT IIf(something = 'Some value', True, False) FROM somewhere;
In Access, you can use a DCount expression to count the number of rows where your something field contains 'some value'. Here is an example copied from the Immediate window:
Debug.Print DCount("*", "somewhere", "something='some value'")
1
Debug.Print DCount("*", "somewhere", "something='BOGUS'")
0
You could adapt that to give you True when the count is greater than zero or False for count of zero:
Debug.Print (DCount("*", "somewhere", "something='some value'") > 0)
True
Debug.Print (DCount("*", "somewhere", "something='BOGUS'") > 0)
False
If you want to do it from a query, this one will return -1 for True and zero for False:
SELECT (DCount("*", "somewhere", "something='some value'") > 0) AS value_exists;
Or you could use a Format expression to display those values as strings: "True"; or "False":
SELECT Format(DCount("*", "somewhere", "something='some value'") > 0, 'True/False') AS value_exists;
As the name implies, DLookup is for this:
SomevalueExists = Not IsNull(DLookup("Id", "somewhere", "somefield = somevalue"))
try this:
select case when x is null then false else true end
from (select max(somecol) x
from sometable
where somecol = somevalue) a
just use
select count(*) from tableName where columnName = '$variableInput';
if you plan on reusing this you might as well make it a prepared statement that you can call upon through whichever interface you design to work with your database. If the returned value is greater than zero you know it to be true, for instance
if(preparedStatement($variableInput)>0)
{
$flag = true;
}
else
{
$flag = false;
}

How do I serialize a table for insertion into a database? [duplicate]

This question already has answers here:
method for serializing lua tables
(5 answers)
Closed 8 years ago.
I would like to serialize a table so that I can insert it into a database and retrieve it later on. How would I do this?
maybe like this https://gist.github.com/rangercyh/5814003
local szStr = ""
function print_lua_table (lua_table, indent)
indent = indent or 0
for k, v in pairs(lua_table) do
if type(k) == "string" then
k = string.format("%q", k)
end
local szSuffix = ""
if type(v) == "table" then
szSuffix = "{"
end
local szPrefix = string.rep(" ", indent)
formatting = szPrefix.."["..k.."]".." = "..szSuffix
if type(v) == "table" then
szStr = szStr..formatting
print_lua_table(v, indent + 1)
szStr = szStr..szPrefix.."},"
else
local szValue = ""
if type(v) == "string" then
szValue = string.format("%q", v)
else
szValue = tostring(v)
end
szStr = szStr..formatting..szValue..","
end
end
end
How to serialize Lua value nicely?
local serialize
do
local num_fmt = '%.17g'
local NaN_serialized = { -- This idea was stolen from lua-nucleo
[num_fmt:format(1/0)] = '1/0',
[num_fmt:format(-1/0)] = '-1/0',
[num_fmt:format(0/0)] = '0/0'
}
local function serialize_table(t, indent)
indent = indent or ''
local new_indent = indent..'\t'
if next(t) == nil then
return '{}'
else
local lines = {}
local function add_line(key)
local ser_key = key
if type(key) ~= 'string' or not key:find'^[%a_][%w_]*$' then
ser_key = '['..serialize(key, new_indent)..']'
end
table.insert(lines,
ser_key..' = '..serialize(t[key], new_indent))
end
local other_keys = {}
local keys = setmetatable({number = {}, string = {}},
{__index = function() return other_keys end})
for k in pairs(t) do
table.insert(keys[type(k)], k)
end
table.sort(keys.number)
table.sort(keys.string)
for _, k in ipairs(keys.number) do
add_line(k)
end
for _, k in ipairs(keys.string) do
add_line(k)
end
for _, k in ipairs(other_keys) do
add_line(k)
end
return '{\n'..new_indent..table.concat(lines, ',\n'..new_indent)
..'\n'..indent..'}'
end
end
function serialize(v, indent)
if type(v) == 'string' then
return ('%q'):format(v)
elseif type(v) == 'boolean' then
return tostring(v)
elseif type(v) == 'nil' then
return tostring(v)
elseif type(v) == 'number' then
return (num_fmt:format(v):gsub('^.*', NaN_serialized))
elseif type(v) == 'table' then
return serialize_table(v, indent)
else
error('Can not serialize '..type(v))
end
end
end
-- What it can:
print(serialize(math.huge))
print(serialize'"What\'s up?"\n\t123')
print(serialize{{}, {{}}})
-- And what it can not:
local t = {}
local tt = {[t] = t}
print(serialize(tt)) -- tt is not a tree, so it was serialized incorrectly

Confused with conditional and logical operators - VB.net

I'm kind of new to VB.net, and since I just finished a C# course, the lack of parentheses creates a lot of confusion on how to write certain combinations of operators.
The C# equivalent of the line I am trying to reproduce in VB would be like this :
if ( (a == 0 && b != null) || (a == 1 && c != null) )
I'm have no idea how to write this in VB, I've tried many combinations of And, Or, AndAlso, OrElse, etc. but I can't achieve the desired result.
I can't find any clear example of C# v.s. VB.net comparison on operators, and the notes I have aren't helpful either.
Can someone help me figure this out?
The equals operator is == in C# and = in VB.
if ( (a == 0 && b != null) || (a == 1 && c != null) )
statement; // One single statement only
or
if ( (a == 0 && b != null) || (a == 1 && c != null) ) {
statement; // Any number of statements
}
This online conversion tool will convert it to VB for you:
If (a = 0 AndAlso b IsNot Nothing) OrElse (a = 1 AndAlso c IsNot Nothing) Then
statement
End If
C# && translates to AndAlso in VB.
C# || translates to OrElse in VB.
With these operators the evaluation stops as soon as the result is determined. This is known as "short-circuit" evaluation. E.g. in a && b the result is known to be false if a is false, and b will not be evaluated. This is especially important when the evaluation has side effects, like performing database queries, raising events or modifying data. It is also useful in conditions like these person != null && person.Name == "Doe" where the second would throw an exception if the first term evaluates to false.
The equivalent of the VB And and Or Boolean operators that do not use short-circuit evaluation are & and | in C#. Here all the terms will always be evaluated.
If (a = 0 Or b = 0 And c = 0) Then
statement
End If
if (a = 0 | b = 0 & c = 0) {
statement;
}
The vb.net equivalent would be
If (a = 0 AndAlso b IsNot Nothing) OrElse (a = 1 AndAlso c IsNot Nothing ) Then
Note in c#, it should be a == 0 and not a = 0
Checkout this post with a comprehensive comparison.
if ( (a = 0 && b != null) || (a = 1 && c != null) )
Is equivilent to:
if ( ( a = 0 AndAlso b IsNot Nothing) OrElse (a = 1 AndAlso c IsNot Nothing) )

Lua table.toString(tableName) and table.fromString(stringTable) functions?

I am wanting to convert a 2d lua table into a string, then after converting it to a string convert it back into a table using that newly created string. It seems as if this process is called serialization, and is discussed in the below url, yet I am having a difficult time understanding the code and was hoping someone here had a simple table.toString and table.fromString function
http://lua-users.org/wiki/TableSerialization
I am using the following code in order to serialize tables:
function serializeTable(val, name, skipnewlines, depth)
skipnewlines = skipnewlines or false
depth = depth or 0
local tmp = string.rep(" ", depth)
if name then tmp = tmp .. name .. " = " end
if type(val) == "table" then
tmp = tmp .. "{" .. (not skipnewlines and "\n" or "")
for k, v in pairs(val) do
tmp = tmp .. serializeTable(v, k, skipnewlines, depth + 1) .. "," .. (not skipnewlines and "\n" or "")
end
tmp = tmp .. string.rep(" ", depth) .. "}"
elseif type(val) == "number" then
tmp = tmp .. tostring(val)
elseif type(val) == "string" then
tmp = tmp .. string.format("%q", val)
elseif type(val) == "boolean" then
tmp = tmp .. (val and "true" or "false")
else
tmp = tmp .. "\"[inserializeable datatype:" .. type(val) .. "]\""
end
return tmp
end
the code created can then be executed using loadstring(): http://www.lua.org/manual/5.1/manual.html#pdf-loadstring if you have passed an argument to 'name' parameter (or append it afterwards):
s = serializeTable({a = "foo", b = {c = 123, d = "foo"}})
print(s)
a = loadstring(s)()
The code lhf posted is a much simpler code example than anything from the page you linked, so hopefully you can understand it better. Adapting it to output a string instead of printing the output looks like:
t = {
{11,12,13},
{21,22,23},
}
local s = {"return {"}
for i=1,#t do
s[#s+1] = "{"
for j=1,#t[i] do
s[#s+1] = t[i][j]
s[#s+1] = ","
end
s[#s+1] = "},"
end
s[#s+1] = "}"
s = table.concat(s)
print(s)
The general idea with serialization is to take all the bits of data from some data structure like a table, and then loop through that data structure while building up a string that has all of those bits of data along with formatting characters.
How about a JSON module? That way you have also a better exchangeable data. I usually prefer dkjson, which also supports utf-8, where cmjjson won't.
Under the kong works this
local cjson = require "cjson"
kong.log.debug(cjson.encode(some_table))
Out of the kong should be installed package lua-cjson https://github.com/openresty/lua-cjson/
Here is a simple program which assumes your table contains numbers only. It outputs Lua code that can be loaded back with loadstring()(). Adapt it to output to a string instead of printing it out. Hint: redefine print to collect the output into a table and then at the end turn the output table into a string with table.concat.
t = {
{11,12,13},
{21,22,23},
}
print"return {"
for i=1,#t do
print"{"
for j=1,#t[i] do
print(t[i][j],",")
end
print"},"
end
print"}"
Assuming that:
You don't have loops (table a referencing table b and b referencing a)
Your tables are pure arrays (all keys are consecutive positive integers, starting on 1)
Your values are integers only (no strings, etc)
Then a recursive solution is easy to implement:
function serialize(t)
local serializedValues = {}
local value, serializedValue
for i=1,#t do
value = t[i]
serializedValue = type(value)=='table' and serialize(value) or value
table.insert(serializedValues, serializedValue)
end
return string.format("{ %s }", table.concat(serializedValues, ', ') )
end
Prepend the string resulting from this function with a return, store it on a .lua file:
-- myfile.lua
return { { 1, 2, 3 }, { 4, 5, 6 } }
You can just use dofile to get the table back.
t = dofile 'myfile.lua'
Notes:
If you have loops, then you will have
to handle them explicitly - usually with an extra table to "keep track" of repetitions
If you don't have pure arrays, then
you will have to parse t differently,
as well as handle the way the keys are rendered (are they strings? are they other tables? etc).
If you have more than just integers
and subtables, then calculating
serializedValue will be more
complex.
Regards!
I have shorter code to convert table to string but not reverse
function compileTable(table)
local index = 1
local holder = "{"
while true do
if type(table[index]) == "function" then
index = index + 1
elseif type(table[index]) == "table" then
holder = holder..compileTable(table[index])
elseif type(table[index]) == "number" then
holder = holder..tostring(table[index])
elseif type(table[index]) == "string" then
holder = holder.."\""..table[index].."\""
elseif table[index] == nil then
holder = holder.."nil"
elseif type(table[index]) == "boolean" then
holder = holder..(table[index] and "true" or "false")
end
if index + 1 > #table then
break
end
holder = holder..","
index = index + 1
end
return holder.."}"
end
if you want change the name just search all compileTable change it to you preferred name because this function will call it self if it detect nested table but escape sequence I don't know if it work
if you use this to create a lua executable file that output the table it will ge compilation error if you put new line and " sequence
this method is more memory efficient
Note:
Function not supported
User data I don't know
My solution:
local nl = string.char(10) -- newline
function serialize_list (tabl, indent)
indent = indent and (indent.." ") or ""
local str = ''
str = str .. indent.."{"
for key, value in pairs (tabl) do
local pr = (type(key)=="string") and ('["'..key..'"]=') or ""
if type (value) == "table" then
str = str..nl..pr..serialize_list (value, indent)..','
elseif type (value) == "string" then
str = str..nl..indent..pr..'"'..tostring(value)..'",'
else
str = str..nl..indent..pr..tostring(value)..','
end
end
str = str:sub(1, #str-1) -- remove last symbol
str = str..nl..indent.."}"
return str
end
local str = serialize_list(tables)
print('return '..nl..str)