Check changes

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Check changes

22 Oct 2013, 13:49

Hello!
I have two variables, Var1 and Var2.
Both variables contain text information.
I want to check if the variables contain the letter "u"

if only one variable contain "u", should some things be done
if both variables contain "u" or both lacks "u", nothing shall be done.

How can I make the check?
//Jan
Last edited by Albireo on 22 Oct 2013, 13:51, edited 1 time in total.
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Check changes

22 Oct 2013, 13:50

Refer the documentation for InStr().
My Scripts and Functions: V1  V2
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Re: Check changes

22 Oct 2013, 14:13

Thanks!
it seems to work!
Maybe can be done in a simpler way!

Code: Select all

#NoEnv
#SingleInstance force
SetBatchLines -1
SetWorkingdir  %A_ScriptDir%
AutoTrim On

Var1 = u
Var2 = u
Var1 = o1%Var1%
Var2 = o2%Var2%

If !(( InStr(Var1, "u") and InStr(Var2, "u") ) or ( !InStr(Var1, "u") and !InStr(Var2, "u") ))
	MsgBox 64, %A_ScriptName% - Row %A_LineNumber%, Both NOT same .:`nVar1 = %Var1% `nVar2 = %Var2%
User avatar
SKAN
Posts: 1551
Joined: 29 Sep 2013, 16:58

Re: Check changes

22 Oct 2013, 14:24

Code: Select all

If ( !!InStr( Var1,"u" ) + !!InStr( Var2,"u" ) = 1 )
    MsgBox Bingo!
Edit
The above simplified:

Code: Select all

Condition1 := InStr( Var1,"u" ) ? 1 : 0
Condition2 := InStr( Var2,"u" ) ? 1 : 0
 
If ( Condition1 + Condition2 = 1 )
    MsgBox Do something!
else
If ( Condition1 + Condition2 = 2 )
    MsgBox Do nothing!
else
If ( Condition1 + Condition2 = 0 )
    MsgBox Do nothing!
Albireo
Posts: 1777
Joined: 16 Oct 2013, 13:53

Re: Check changes

22 Oct 2013, 14:49

Great!
Thanks!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], peter_ahk and 138 guests