Sign in to follow this  
Followers 0
Stealth111

Need Help- Auto Adjusting Progress Bar..

10 posts in this topic

#1 ·  Posted (edited)

I HAVE searched the forums and tried examples of what I have found, but most of the examples I have found are always very different from the next, so I am having a hard time trying to impliment it in the right way.. Here goes I am running an autoit script that starts out by running a .vbs script to enumerate all the computers from my active directory domain into a text file called pclist.txt (depending on the building there may be 16 computers to 128 computers in the list ( 6 different buildings)), with 1 computername on each line..then i am pinging these computers in the list, and depending on if they are alive or not, they get put into either List1 (alive) or List2 (dead) and the third List3 is a total of all the computer names from the list gathered by the .vbs file ((Since I also am having a hard time porting the vbs script to autoit successfully...)). NOW here is where the problem is for me.. I want to have a ProgressBar showing the status of processed computers.. A progressbar based on 100% is easy enough, but if I move the same code to my script lets say with 14 computers in the list, the progressbar goes from start to about 14% of the total bar and then it is done.. I need help on trying to make the progressbar DYNAMIC so it goes from start to end based on the number of computers in the list, using the same progressbar in the script.. If there are 14 comuputers then progressbar will go from beginning to end when it reaches 14th process in loop it will be at end, but I also need it to do the same when it has 55 items in the list or 177 items in the list, I want the progressbar to adjust its progress based on actual scale of what it is processing.. I hope someone can understand what I need..

; run external vbs script ..  :)
RunWait("wscript EnumerateAdComputers.vbs")
; make the lists
$List1 = GUICtrlCreateList("", 24, 40, 97, 920)
$List2 = GUICtrlCreateList("", 160, 40, 97, 920)
; make the progressbar
$progressbar1 = GUICtrlCreateProgress (24,960,380,20,$PBS_SMOOTH)
    GUICtrlSetColor(-1,0xFFFF00)


;the function

Func ProdList()
    $list = FileOpen("Pclist.txt", 0)
    $FileCount = _FileCountLines("PcList.txt")

        for $i = 1 to $FileCount
           
            $area = FileReadLine($list)
            $error = @error
                if $error = -1 Then
                                
                ExitLoop
            EndIf

            ping($area,50)
            
            if @error <> 0 Then
                                 _GUICtrlListAddItem($List2, $area)
                 GUICtrlSetData ($progressbar1,$i)
                     
                     
                Else
                     _GUICtrlListAddItem($List1, $node)
            GUICtrlSetData ($progressbar1,$i)
                    
            EndIf
                           
        Next

I have the : GUICtrlSetData ($progressbar1,$i) in both places, because I want the progress to go up no matter which list the computer gets added to, I need the progressbar to reflect the change, I have left out the rest of the slop script to make short of it.. So if my pclist.txt has 14 computers in it, they get pinged, if it is dead it gets dumped into List2 and the progressbar should go up a bit, but if it did respond to the ping then it gets dumped into list1 and the progress should go up by a bit as well, till the loop has processed all 14 systems,, which it does, and I end up with 14 total systems in 2 seperate lists, but my progressbar sits at about 14% as it by default must be assuming the total items is 100, which I understand, but I need to total items of the progressbar to be based on the $FileCount number, if I could achieve that, in my sample script then when the loop was done the progressbar would be full. and if the list had 67 computers it would be the same, all full, when it processed the last computer from the list.. Any help would be greatly appreciated..

Edited by Stealth111

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

A progressbar based on 100% is easy enough

so why dont you make it a percentage. I will assume you dont know how to do this so i will show you (no offense if you do).

GUICtrlSetData ($progressbar1,($i/$FileCount)*100)

Edited by Cue

Share this post


Link to post
Share on other sites

Thats EXACTLY what I needed, I meant making a progressbar based on a standard fixed count to 100% was easy, but I did NOT know the command to make it a percentage based on number of items.. Thanks very much for your help..

Share this post


Link to post
Share on other sites

Func ProdList()
        $list = FileOpen("Pclist.txt", 0)
        $FileCount = _FileCountLines("PcList.txt")
        
        for $i = 1 to $FileCount
          
            $area = FileReadLine($list)
            if @error= -1 Then ExitLoop
            ping($area,50)
            
            if @error <> 0 Then
                _GUICtrlListAddItem($List2, $area)
            Else
                _GUICtrlListAddItem($List1, $node)
            EndIf
            GUICtrlSetData ($progressbar1,($i/$FileCount)*100)
        Next
EndFunc

Why dont you store the list in an ini then you can have 2 sections pingable and unpingable pc names as keys with extented information as values using

1 = Host is offline

2 = Host is unreachable

3 = Bad destination

4 = Other errors

ping time

Share this post


Link to post
Share on other sites

Instead of writing each line to the list as it gets processed by the following function, is it possible to have the function working in the background and writing the results to 2 different files, so that after the function is done then all the lines from each respective file goes to the list it is assigned?? so they show up instantly, instead of slowly 1 line at a time in the $List1 and $List2..

Func ProdList()
        $list = FileOpen("Pclist.txt", 0)
        $FileCount = _FileCountLines("PcList.txt")
       
        for $i = 1 to $FileCount
         
            $area = FileReadLine($list)
            if @error= -1 Then ExitLoop
            ping($area,50)
           
            if @error <> 0 Then
                _GUICtrlListAddItem($List2, $area)
            Else
                _GUICtrlListAddItem($List1, $area)
            EndIf
            GUICtrlSetData ($progressbar1,($i/$FileCount)*100)
        Next
EndFunc

the above code you fixedup for me worked perfectly, but could this be changed from:

_GUICtrlListAddItem($List2, $area) to something like this:

_GUICtrlListAddItem((some other file), $area) then after the function is done do like this??

_GUICtrlListAddItem($List2, (some other file)), but it would add ALL the lines from the (some other file) that was populated by the new function??

Share this post


Link to post
Share on other sites

Iam not sure i understand what you mean? do you mean finish the ping process and store the results in a variable (an array or something) then populating the list with the results.

_GUICtrlListAddItem((some other file), $area) this makes no sense by 'some other file' do you mean some other variable

Share this post


Link to post
Share on other sites

Do you mean like this... I have not tested this code make sure they go in the right list.

Func ProdList()
        $list = FileOpen("Pclist.txt", 0)
        $FileCount = _FileCountLines("PcList.txt")
        local $PingSuccess[1],$PingFail[1]
        
        
        for $i = 1 to $FileCount
          
            $area = FileReadLine($list)
            if @error= -1 Then ExitLoop
            ping($area,50)
            
            if @error <> 0 Then
                _ArrayAdd($PingSuccess,$area)
            Else
                _ArrayAdd($PingFail,$area)
            EndIf
            GUICtrlSetData ($progressbar1,($i/$FileCount)*100)
        Next
        
        For $i=1 to UBound($PingSuccess)-1
            _GUICtrlListAddItem($List2, $PingSuccess[$i])
        Next
        For $i=1 to UBound($PingFail)-1
            _GUICtrlListAddItem($List1, $PingFail[$i])
        Next
        
EndFunc

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Thanks again Cue for coming to the rescue, it is people like you that makes this community what it is.. I have never been part of any forum where everybody is so helpfull. You really helped me get over some big humps in my program... I am going to TRY to get the other 2 bugs worked out myself hopefully.... 1 is getting this (making it possible to exit the program by clicking the (x) in the top right corner of the GUI):

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case 0
            Sleep(250)
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

to actually work ANYTIME the program is running.. it is right after I created the gui, and after I run the Update() function call.. The problem is that if I click on the X the first loop the program runs it sometimes closes the program, and most of the time the (x) to close the program just does not seem to ever respond, and if it does it is awhile after you clicked it a bunch of times....

The other is going to integrate the active directory vbs script I wrote into AutoIt commands so I wont even have to call an external program at all!!

Thanks again!! :whistle:

Edited by Stealth111

Share this post


Link to post
Share on other sites

look up GUISetOnEvent() this may solve you first problem.

Share this post


Link to post
Share on other sites

in the help file look up "GUI Concepts" this should give you your answer

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