Sign in to follow this  
Followers 0
Hina

A little confusion in code

6 posts in this topic

$var = WinList()

For $i = 1 to $var[0][0]
 ; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
  EndIf
Next

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

I am confuse @ these steps

$i = 1 to $var[0][0]

$var[$i][0] <> "" AND IsVisible($var[$i][1])

Explain what actually $i is doing in the who code & what is $var[0][0] is doing why not we can write $i= 2 & $var[1][0] etc need explanation if possible

Share this post


Link to post
Share on other sites



$var = WinList()

Look up WinList in the help file. It returns an array

For $i = 1 to $var[0][0]
; Only display visble windows that have a title
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
    MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1])
  EndIf
Next

This for loop catches all programs listed by winlist that are actually visible.

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf

EndFunc

The whole reason for the for loop is so you don't have to go through each part of the array manually


Giggity

Share this post


Link to post
Share on other sites

Please someone explain it to me.

To youknowwho4eva

The point which U are talking about it I have idea about it but I want the logic of my above mention code. Please someone help me

Share this post


Link to post
Share on other sites

FOR loops are to automatically go through it for as many times as you specify.. FOR $i=0 TO 10 goes through the loop 10 times.. possibly 11..(does it start at the number?) any how... and this

$var[$i][0] <> "" AND IsVisible($var[$i][1])

means if the list isnt blank and if the first one is visable

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

FOR loops are to automatically go through it for as many times as you specify.. FOR $i=0 TO 10 goes through the loop 10 times.. possibly 11..(does it start at the number?) any how...

The value starts with the first number. So "0 To 10" results in 11 loops.

and this

means if the list isnt blank and if the first one is visableClose. If means if that particular element is not empty (WinList returns the title in [n][0] and the handle in [n][1]), and the window with that title is visible (checked by the IsVisible function).

This method is not actually good practice unless you know for sure the windows you are looking for have a non-blank title and only one instance. It would be better to use $var[$i][1] (the handle) because every window has one and it is always unique.

:D

P.S. Just for fun, note also that the start, end, and step numbers in a For/Next loop don't have to be integers:

For $n = 0.5 To 5
    ConsoleWrite("$n = " & $n & @LF)
Next
ConsoleWrite(@LF)
For $i = 0.5 To 5 Step 0.3
    ConsoleWrite("$i = " & $i & @LF)
Next

:o

Edited by PsaltyDS

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

Share this post


Link to post
Share on other sites

there you go.. learn something new everyday

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