AHKStudent wrote: ↑06 Aug 2018, 14:17
I know how to check if variable is empty
if (foo = "") or if (foo != "") or even if !(foo = "")
In the examples you presented, it's if (foo = "") that checks if the variable is empty.
if (foo != "") or if !(foo = "") checks if the variable contains something. Maybe this was confusing you right off the bat.
How do I check if variable has data
if (foo != "") or if !(foo = "") ; if the variable is not empty (thus has something)
My case is that if variable is empty I want my script to go on, I don't want to create a gosub, label etc
The opposite of what your are saying is, if the variable is not empty, do something. Which is the below (like what Just me explained)
But you can also pick, if the variable is empty, do something.
You usually won't need to check if the variable is empty and do nothing, because you can check if it's not empty and do something or check if it' empty and do something.
But if you must, Jeeswg gave you solutions, to do nothing.
Code: Select all
if (foo != "")
{
}
- Or Sleep 0:
if (foo != "")
Sleep, 0
if variable has data do the following
You can also suggest if you like something else to do so the script keeps moving along other than gosub
Code: Select all
if (foo != "")
{
keep moving ; what is this keep moving command?
}
else
{
do these commands
}
Your code is arguably demonstrating a problem with logic. You have to flip it, and see the opposite as well, which will be the solution.
You likely want, if not empty, do something...
Code: Select all
if !(foo = "") ; if not empty
{
Do Something
}
or you can do, if empty, do something
Code: Select all
if (foo = "") ; if empty
{
Do Something
}
If you are having trouble seeing the opposite to get the solution, you can continue with that thinking pattern and simply have code that does nothing. Nothing wrong with it, but it's arguably wasteful code, because it's not doing anything. But as Jeeswg has mentioned, it can sometimes make things logically clear, as to what you are doing or want to do. It's more important that you understand the code that you write, even when looking at it months or years later, and that your program does what you want. Functionality over style points.
Code: Select all
if (foo != "")
{
}
else
{
Do Something
}
- Or Sleep 0:
if (foo != "")
{
Sleep, 0
}
else
{
Do Something
}
Edited to be more clear.