# Logic

## Recommended Posts

Im trying to find if a value occurs twice after a given in an array

But I cant get it right, probably multiple mistakes here

I cant test it cause my PC with autoit is down.

Local \$ablah[9] = [y,y,d,f,y,s,y,d,k]
_function(\$ablah)
Func _function(\$ablah)
If \$ablah[0] = \$ablah[1] Then
For \$i = 2 To 8
If \$ablah[\$i] = \$ablah[0] Then
\$x = \$i
For \$z = \$x To 8
If \$ablah[\$z] = \$ablah[0] Then
\$bool = True
EndIf
Next
EndIf
Next
EndIf
Return \$bool
EndFunc

Appreciate any help with my useless logic.

EDIT: not much

Edited by JohnOne

Monkey's are, like, natures humans.

##### Share on other sites

exactly 2 times or 2 and more ?

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

\$ablah[0] and \$ablah[1] will always be the same

Im trying a function to see if two others between [2] to [9] are equal to [0]

EDIT: sorry, it could be ubound(\$ablah)

Edited by JohnOne

Monkey's are, like, natures humans.

##### Share on other sites

\$ablah[0] and \$ablah[1] will always be the same

Im trying a function to see if two others between [2] to [9] are equal to [0]

Ok, but what about if it are 3 others?

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Just update the if to >= if its 2 or more:

Local \$ablah[9] = ["y","y","d","f","y","","y","dx","k"]
If _function(\$ablah) then
ConsoleWrite("there are 2 or more equal values in the array" & @CR)
EndIf
Func _function(\$ablah)
\$count = 0
For \$i = 2 To 8
If \$ablah[0] == \$ablah[\$i] Then \$count += 1
Next
If \$count = 2 then Return True
Return False
EndFunc
Edited by Jos

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

2 others or more should male \$bool = True

Monkey's are, like, natures humans.

##### Share on other sites

Local \$ablah[9] = ["y","y","d","f","y","","y","dx","k"]
If _function(\$ablah) then
ConsoleWrite("there are 2 or more equal values in the array" & @CR)
EndIf
Func _function(\$ablah)
\$count = 0
For \$i = 2 To 8
If \$ablah[0] == \$ablah[\$i] Then \$count += 1
If \$count = 2 then Return True
Next
Return False
EndFunc

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Thanks Jos, Appreciated

If you can be bothered, I have not been able to discover why/if == and = are diferent and mean diferent things, I have looked tons of times but cannot grast it.

Any link to an explaination ?

Thanks again.

Monkey's are, like, natures humans.

##### Share on other sites

Thanks Jos, Appreciated

If you can be bothered, I have not been able to discover why/if == and = are diferent and mean diferent things, I have looked tons of times but cannot grast it.

Any link to an explaination ?

Thanks again.

From the helpfile:

= Tests if two values are equal (case insensitive if used with strings). e.g. If \$var= 5 Then (true if \$var equals 5)

== Tests if two values are equal (case sensitive if used with strings)

So:

If "a" = "A" then ; is true
If "a" == "A" then ; is false

Live for the present,
Dream of the future,
Learn from the past.

##### Share on other sites

Thanks once again, lesson complete.

I do remember reading about that before I even started to try autoit3 but could never find it again

Thanks for you help and time.

Monkey's are, like, natures humans.

##### Share on other sites

Thanks once again, lesson complete.

I do remember reading about that before I even started to try autoit3 but could never find it again

Thanks for you help and time.

Its in:"Language reference"/Operators

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account