How to check if a string contains text or is it empty?
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: How to check if a string contains text or is it empty?
Einfach nur ein toller Typ.
Re: How to check if a string contains text or is it empty?
I do not understand how this can be useful in my case.
Re: How to check if a string contains text or is it empty?
I tried this but it didn’t work
Code: Select all
p::
Field = ""
Loop, parse, Field,
If ( Field:= "" )
{
send zzz
}
return
Re: How to check if a string contains text or is it empty?
Code: Select all
;either:
if (var = "")
;or:
if (var == "")
;==================================================
;note:
if (var := "")
;is equivalent to:
var := ""
if (var = "")
Code: Select all
vText := "abc,def,,ghi"
Loop Parse, vText, % ","
{
if (A_LoopField = "")
{
MsgBox, % A_Index
}
}
return
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
- divanebaba
- Posts: 805
- Joined: 20 Dec 2016, 03:53
- Location: Diaspora
Re: How to check if a string contains text or is it empty?
And I do not understand, how this could not be useful in your case.
Code: Select all
var := "abc"
F6::
if var is alpha
msgbox, var is just text
else
msgbox, var is or contains non-text-elements
return
Einfach nur ein toller Typ.
Re: How to check if a string contains text or is it empty?
MsgBox showes "3" if the line contain abc, or 123, or empty. No difference.jeeswg wrote: ↑14 Sep 2019, 18:11Perhaps for your script, you want something like this:Code: Select all
vText := "abc,def,,ghi" Loop Parse, vText, % "," { if (A_LoopField = "") { MsgBox, % A_Index } } return
https://vimeo.com/user88307319/review/360050971/9fdd52105c
Your code same.divanebaba wrote: And I do not understand, how this could not be useful in your case.Code: Select all
var := "abc" F6:: if var is alpha msgbox, var is just text else msgbox, var is or contains non-text-elements return
Sorry
Re: How to check if a string contains text or is it empty?
How do you read the string (line)?MsgBox showes "3" if the line contain abc, or 123, or empty. No difference.
Re: How to check if a string contains text or is it empty?
I just go to a new line.
I want the script to understand if there is text in it or is it empty. And based on the result, the next command starts, or does not start.
Re: How to check if a string contains text or is it empty?
jeeswg wrote: ↑14 Sep 2019, 18:11Perhaps for your script, you want something like this:Code: Select all
vText := "abc,def,,ghi" Loop Parse, vText, % "," { if (A_LoopField = "") { MsgBox, % A_Index } } return
The "3" is showing you the empty field, which is at the 3rd position (A_Index).MsgBox showes "3" if the line contain abc, or 123, or empty. No difference.
Instead of A_Index, he could have put a MsgBox that said Empty Field Found (MsgBox, Empty Field Found!)
Jeeswg answered your question, showing you if a field is empty or not. Instead of MsgBox, you could put some other code.
Alternative Example 1
Code: Select all
vText =
(
abc, LoopField 1
def, LoopField 2
ghi, LoopField 4
)
Loop Parse, vText, `n
{
if (A_LoopField = "")
{
MsgBox,,, The LoopField Number %A_Index% Is Empty!
}
}
return
Code: Select all
vText =
(
abc, LoopField 1
def, LoopField 2
ghi, LoopField 4
)
Loop Parse, vText, `n
{
if (A_LoopField = "")
{
continue
}
if (A_LoopField != "")
{
MsgBox % A_LoopField
}
}
return
Re: How to check if a string contains text or is it empty?
Just so you are aware of the errors in your original code, you used = and := incorrectly in both cases. You used the assignment operator := to do an if comparison. And you used = as an assignment operator with quotes, which you would only do with the expression assignment operator :=. Also, to just see if Field is blank, you don't need a loop:reluct wrote: ↑14 Sep 2019, 17:32I tried this but it didn’t workCode: Select all
p:: Field = "" Loop, parse, Field, If ( Field:= "" ) { send zzz } return
Code: Select all
Field := ""
If ( Field = "" )
{
MsgBox, zzz
}
return
Field =
Re: How to check if a string contains text or is it empty?
I totally don’t understand what your code does. It does not solve my problem. Maybe I'm confused with terminology. Or I’m explaining something wrong.
Imagine I'm completing sentences now, press enter. I will change to a new line where there is no text. Here the script should determine if there is text or not. I don’t know why I can’t do this with scripts that you call true.
Imagine I'm completing sentences now, press enter. I will change to a new line where there is no text. Here the script should determine if there is text or not. I don’t know why I can’t do this with scripts that you call true.
Re: How to check if a string contains text or is it empty?
Are you trying to get data from a control of a GUI?
In that case, you need to use ControlGet, ControlGetText, or GuiControlGet. The usual difference between ControlGet and GuiControlGet, is if you are getting the data from a non-AutoHotkey GUI, use ControlGet or ControlGetText, or from an AutoHotkey created GUI, use GuiControlGet.
To find out the name of the control, you could use WindowSpy.ahk, usually in the directory of where you installed AutoHotkey.
https://www.autohotkey.com/docs/commands/ControlGetText.htm
ControlGetText, OutputVar , Control, WinTitle
Example
In that case, you need to use ControlGet, ControlGetText, or GuiControlGet. The usual difference between ControlGet and GuiControlGet, is if you are getting the data from a non-AutoHotkey GUI, use ControlGet or ControlGetText, or from an AutoHotkey created GUI, use GuiControlGet.
To find out the name of the control, you could use WindowSpy.ahk, usually in the directory of where you installed AutoHotkey.
https://www.autohotkey.com/docs/commands/ControlGetText.htm
ControlGetText, OutputVar , Control, WinTitle
Example
Code: Select all
p::
ControlGetText, Field, Edit1, WinTitleName
If (Field = "")
{
send zzz
}
return
- flyingDman
- Posts: 2817
- Joined: 29 Sep 2013, 19:01
Re: How to check if a string contains text or is it empty?
@reluct As you seem to be somewhat frustrated by the responses you received, you might want to provide (much more) detailed information about your circumstance. Are you working in a word processor, in a box on a web page, in a cell of spreadsheet? can you capture the existing text using "ctrl A"? etc etc . All respondents have provided code that helps you resolve exactly what it says in the subject heading "How to check if a string contains text or is it empty?". There is obviously more to that ...
14.3 & 1.3.7
Re: How to check if a string contains text or is it empty?
Yes, I'm kind of frustrated. But this is not a problem, it is better to be frustrated with answers than when there are no answers at all. I recorded a video from the screen, I hope this helps.flyingDman wrote: ↑15 Sep 2019, 12:10@reluct As you seem to be somewhat frustrated by the responses you received, you might want to provide (much more) detailed information about your circumstance. Are you working in a word processor, in a box on a web page, in a cell of spreadsheet? can you capture the existing text using "ctrl A"? etc etc . All respondents have provided code that helps you resolve exactly what it says in the subject heading "How to check if a string contains text or is it empty?". There is obviously more to that ...
https://youtu.be/87s6yrun_U8
Re: How to check if a string contains text or is it empty?
I've added https://biga-ahk.github.io/biga.ahk/#/?id=isundefined to biga.ahk to address cases like this. Perhaps that is of use to you. But if you are struggling with basics it may not be.
Code: Select all
A:= new biga()
A.isUndefined(neverIntializedVar)
; => true
A.isUndefined("")
; => true
Re: How to check if a string contains text or is it empty?
u want to determine whether a textbox contains anything.
try @SOTE s suggestion. if the app doesnt comprise standard gui controls, ull have to find another way of grabbing the text - ctrlA ctrlC / MSAA ACC / ocr
it is only after uve grabbed it, that u can test whether its empty
try @SOTE s suggestion. if the app doesnt comprise standard gui controls, ull have to find another way of grabbing the text - ctrlA ctrlC / MSAA ACC / ocr
it is only after uve grabbed it, that u can test whether its empty
Last edited by swagfag on 15 Sep 2019, 14:37, edited 1 time in total.
Re: How to check if a string contains text or is it empty?
I think you are trying to grab data off a website but none of the posts say so. Your video is unclear and also doesn't show any ahk code so we still don't know what you're working with.
Re: How to check if a string contains text or is it empty?
This is Program Anki 2.0(not 2.1 !!!) https://youtu.be/87s6yrun_U8
Re: How to check if a string contains text or is it empty?
@SOTE s suggestion not work.swagfag wrote: ↑15 Sep 2019, 14:32u want to determine whether a textbox contains anything.
try @SOTE s suggestion. if the app doesnt comprise standard gui controls, ull have to find another way of grabbing the text - ctrlA ctrlC / MSAA ACC / ocr
it is only after uve grabbed it, that u can test whether its empty
But why doesn't Loop (parse a string) capture text?
Who is online
Users browsing this forum: No registered users and 321 guests