Page 1 of 1

help with - if statement with a string

Posted: 03 Dec 2021, 03:36
by joekingcool
im having trouble remembering how to do this. i have output from a command into the clip. the results are true or false. so if true do this, if false do this. sounds simple but im missing something. my code is below.

Code: Select all

runwait, powershell -Command "$DGVerifyWarn.Length -ne 0" | Clip,, Hide
DG_Enabled = %clipboard%

StringReplace, DG_Enabled, DG_Enabled, " ", , All
msgbox %DG_Enabled%

if (DG_Enabled = "False")
Gui,1:Add, Text, +Center Cred x10 y435 w130 h30 , DG_Disabled
if (DG_Enabled = "True")
Gui,1:Add, Text, +Center cLime x10 y435 w130 h30 , DG_Enabled
many thanks as always:)

edit-- another thing i noticed is if i ouput to text doc, it has a return after the string. the msgbox shows up correct and the output to the text doc except for the return after it.

Re: help with - if statement with a string  Topic is solved

Posted: 03 Dec 2021, 05:59
by mikeyww
You have your answer due to the CRLF sequence.

Code: Select all

Clipboard =
RunWait, powershell -Command "$DGVerifyWarn.Length -ne 0" | Clip,, Hide
ClipWait, 0
If ErrorLevel {
 MsgBox, 48, Error, An error occurred while waiting for the clipboard.
 Return
}
If ("True" = DG_Enabled := Trim(Clipboard, "`r`n"))
     color = Lime
Else color = Red
Gui, Add, Text, +Center c%color% x10 y435 w130 h30, DG_Enabled is %DG_Enabled%
Gui, Show,, DG

Re: help with - if statement with a string

Posted: 03 Dec 2021, 06:16
by joekingcool
thanks!!, i just found a solution minutes ago, lol :) although your solution is cleaner!

https://www.autohotkey.com/board/topic/53853-if-statement-comparing-two-variables/