Combine two if statments Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tabr3
Posts: 27
Joined: 25 Feb 2024, 04:06

Combine two if statments

21 Mar 2024, 06:33

Code: Select all


; working

if ramdom_num in %banlist%
    continue

if ramdom_num in %current_list%
    continue
    
;---------------------

;  as one
if ramdom_num in %banlist% or ramdom_num in %current_list%
    continue
    
The combined statement is runnable, but I don't think it checks the second half after "or".
Is this because these are not expression ? How to make them as one line?
User avatar
mikeyww
Posts: 27320
Joined: 09 Sep 2014, 18:38

Re: Combine two if statments

21 Mar 2024, 06:42

There could be two different approaches here.
  1. Use regular expressions or InStr instead of "in" syntax
  2. Assign the results to two variables, and then use "OR" with those variables
Last edited by mikeyww on 21 Mar 2024, 06:46, edited 1 time in total.
User avatar
boiler
Posts: 17332
Joined: 21 Dec 2014, 02:44

Re: Combine two if statments  Topic is solved

21 Mar 2024, 06:42

Code: Select all

if ramdom_num in %banlist%,%current_list%
User avatar
mikeyww
Posts: 27320
Joined: 09 Sep 2014, 18:38

Re: Combine two if statments

21 Mar 2024, 06:46

I missed the third option! Good one.
User avatar
boiler
Posts: 17332
Joined: 21 Dec 2014, 02:44

Re: Combine two if statments

21 Mar 2024, 06:48

Note that the if var in… syntax does not allow the use of expressions, so OR cannot be used with it.
User avatar
mikeyww
Posts: 27320
Joined: 09 Sep 2014, 18:38

Re: Combine two if statments

21 Mar 2024, 06:52

A more general approach without OR and without in is below, though in v2 one might use arrays instead of comma-delimited strings.

Code: Select all

#Requires AutoHotkey v1.1.33.11
banlist      := "ab,cd,ef"
current_list := "gh,ij"
random_num   := "gh"
random_num   := "cdd"
o            := ","
If InStr(o banlist o current_list o, o random_num o)
     MsgBox 64, Success, Found!
Else MsgBox 48, Failure, Not found!

Code: Select all

#Requires AutoHotkey v2.0
banlist      := 'ab,cd,ef'
current_list := 'gh,ij'
random_num   := 'gh'
random_num   := 'cdd'
o            := ','
If InStr(o banlist o current_list o, o random_num o)
     MsgBox 'Found!'    , 'Success', 'Iconi'
Else MsgBox 'Not found!', 'Failure', 'Icon!'
tabr3
Posts: 27
Joined: 25 Feb 2024, 04:06

Re: Combine two if statments

21 Mar 2024, 09:09

Code: Select all

banlist:="8.1.7.29.30.36.48.28.5.13.24.31.32.36.39"
draw:=10

banlist:=StrReplace(banlist, "." , ",")     ; in/contains may not deal with . but ,
loop %draw% {
loop {

Random , ramdom_num , 1, 49

if ramdom_num in %banlist%
continue

if ramdom_num in %current_list% 
continue

current_list.=ramdom_num . ","
++six

if (six = 6) { 
current_list:=SubStr(current_list, 1, -1)
sort, current_list, N D,
outlist.=current_list . "`n"
current_list:=six:=""
break
}
}
}

tooltip %outlist%
return
Thank everyone but still not working for this.
I tried instr before, but if the banlist contains 32, then 3 and 2 will also not be output.
User avatar
mikeyww
Posts: 27320
Joined: 09 Sep 2014, 18:38

Re: Combine two if statments

21 Mar 2024, 10:16

It worked here.
tabr3
Posts: 27
Joined: 25 Feb 2024, 04:06

Re: Combine two if statments

21 Mar 2024, 11:29

mikeyww wrote:
21 Mar 2024, 10:16
It worked here.
My bad, it is working now :thumbup:

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mikeyww, newbieforever, RussF and 121 guests