Jump to content

conditional logic in a FOR loop


gcue
 Share

Recommended Posts

im doing a search within an array and if the search is successful it outputs some values based on your query

but if the search is not successful id like to indicate that

so im trying to incorporate this into my loop but along the way, the values get switched around and i end up with false outputs

If GUICtrlRead($initials) <> $avOut[$u][13] Then
           MsgBox(0, "", GUICtrlRead($initials) & " was not found.")
           ExitLoop
    EndIf

here's my for loop

For $u = 1 To $avOut[0][0]
                
        
        If GUICtrlRead($initials) = $avOut[$u][13] Then

            If $avOut[$u][3] <> "LAPTOP" And $avOut[$u][3] <> "COMPUTER" Then
                $type = "No PCs are associated with " & GUICtrlRead($initials)
            EndIf

            If $avOut[$u][3] = "LAPTOP" Then
                $type = ("L" & $avOut[$u][0])
            EndIf
            
            If $avOut[$u][3] = "COMPUTER" Then
                $type = ("D" & $avOut[$u][0])
            EndIf

            MsgBox(0, "", $type)
                            
        EndIf
    Next
Link to comment
Share on other sites

im doing a search within an array and if the search is successful it outputs some values based on your query

but if the search is not successful id like to indicate that

so im trying to incorporate this into my loop but along the way, the values get switched around and i end up with false outputs

If GUICtrlRead($initials) <> $avOut[$u][13] Then
           MsgBox(0, "", GUICtrlRead($initials) & " was not found.")
           ExitLoop
    EndIf

here's my for loop

For $u = 1 To $avOut[0][0]
                
        
        If GUICtrlRead($initials) = $avOut[$u][13] Then

            If $avOut[$u][3] <> "LAPTOP" And $avOut[$u][3] <> "COMPUTER" Then
                $type = "No PCs are associated with " & GUICtrlRead($initials)
            EndIf

            If $avOut[$u][3] = "LAPTOP" Then
                $type = ("L" & $avOut[$u][0])
            EndIf
            
            If $avOut[$u][3] = "COMPUTER" Then
                $type = ("D" & $avOut[$u][0])
            EndIf

            MsgBox(0, "", $type)
                            
        EndIf
    Next
Just add an ELSE clause to you If/EndIf. (See the help file.)

:P

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

yea i did that but along the way the values of $type change so the results are inaccurate the second time around

thats why im confused =/

ElseIF is what you want to do. It's saying "If it is not this, then is it this?"

If GUICtrlRead($initials) = $avOut[$u][13] Then

            If $avOut[$u][3] <> "LAPTOP" And $avOut[$u][3] <> "COMPUTER" Then
                $type = "No PCs are associated with " & GUICtrlRead($initials)
        
            ElseIf $avOut[$u][3] = "LAPTOP" Then
                $type = ("L" & $avOut[$u][0])

            ElseIf $avOut[$u][3] = "COMPUTER" Then
                $type = ("D" & $avOut[$u][0])
                
            EndIf

            MsgBox(0, "", $type)

        EndIf

Help?

Link to comment
Share on other sites

this is a query of a computer inventory.

so the person inputs an account name ($initials) and hopes to get the PCs that belong to that person

i can see two problems happening:

1. the person is not found at all

2. the person does not have any PCs associated to him/her

im trying to account for both

Link to comment
Share on other sites

you can indicate a flag" that will indicate if you have found what you were looking for

something like this

$flag=False
For $u=1 to 10
 If <searrch> Than
   Msg("FOUND")
   $flag=True
   Exitloop
 Endif
 do something...
next
if $flag==False Then Msg("I did not found it :(")

I hope that helped

I ran. I ran until my muscles burned and my veins pumped battery acid. Then I ran some more.

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...