help with - if statement with a string Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
joekingcool
Posts: 238
Joined: 14 Dec 2019, 20:21

help with - if statement with a string

Post by joekingcool » 03 Dec 2021, 03:36

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.

User avatar
mikeyww
Posts: 26589
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 03 Dec 2021, 05:59

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

joekingcool
Posts: 238
Joined: 14 Dec 2019, 20:21

Re: help with - if statement with a string

Post by joekingcool » 03 Dec 2021, 06:16

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/

Post Reply

Return to “Ask for Help (v1)”