Jump to content

Logic


JohnOne
 Share

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

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

Monkey's are, like, natures humans.

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

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

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Developers

$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?

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

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

Link to comment
Share on other sites

  • Developers

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

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

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 ;)

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...