Sign in to follow this  
Followers 0
JohnOne

Logic

11 posts in this topic

#1 ·  Posted (edited)

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

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
Share on other sites



#3 ·  Posted (edited)

$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

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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?

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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.


AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Share this post


Link to post
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

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
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 ;)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0