Responsive loop progress bar - sending me loopy

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
CI_Netops
Posts: 13
Last visit: Tue Nov 10, 2020 9:24 am

Responsive loop progress bar - sending me loopy

Post by CI_Netops »

Hi there

I've read the page on "Responsive forms" quite a few times and i'll be honest I'm having a nightmare figuring out something I believe should be quite simple to understand.

I've created a UI (see attachment). Its pretty basic. it contains the following as you'll see:
* Two checkboxes
* Textbox
* Various buttons
* Listbox
* Richtextbox (for outputting purposes)
* Progressbar (using the 'progress bar - responsive loop' control set)

The listbox accepts CSV input as well as a list from TXT file. These can either be imported (using the button) or dragged and dropped on the box. Items can also be added via the TEXT box and pressing the corresponding button. The LISTBOX also checks to see if value already exists and if it does it wont add it.

'Clear Select' removes selected items from the LISTBOX and 'Clear All' Removes all items.

So onto the issues I'm facing/need help with.

When I click the 'Start Process' button it needs to one of four things depending on the following:
1. if($checkbox1.checkstate -eq unchecked -and $checkbox2.checkstate -eq unchecked){Do something with multiple if statements}
2. if($checkbox1.checkstate -eq checked -and $checkbox2.checkstate -eq checked){Do something with multiple if statements}
3. if($checkbox1.checkstate -eq checked -and $checkbox2.checkstate -eq unchecked){Do something with multiple if statements}
4. if($checkbox1.checkstate -eq unchecked -and $checkbox2.checkstate -eq checked){Do something with multiple if statements}

what ever process is relevant I then need it to loop through the items within the listbox and output certain things to the Richtextbox such as:
listbox item processing
Error doing something
Something completed
Rinse and repeat

So heres issue one - I cant seem to get it to stop looping though the Listbox once its completed? instead it just continuely cycles while the progress steps up to full.

Issue number two, below is obviously the code for the progressbar and my issue is where or how do I put all the above to make it work. As stated right back at the start I'm sure this is me being purely stupid and probably overthinking it but having spent a couple of days reading and trying various things I'm now at your hopefully helpful mercy.

$buttonStartProcess_Click={
#Init CancelLoop
$script:CancelLoop = $false
$buttonCancelProcess.Enabled = $true
#Disable the button so we don't trigger it again
$this.Enabled = $false
#Reset the Progress Bar
$progressbar1.Value = 0

for($i = 0; $i -lt $progressbar1.Maximum; $i++)
{
#----------------------------------------
#Place custom script here
sleep -Milliseconds 200

#----------------------------------------
#process the pending message
[System.Windows.Forms.Application]::DoEvents()

if($script:CancelLoop -eq $true)
{
#Clear the progress bar
$progressbar1.Value = 0
#Exit the loop
break;
}
#Step the progress bar
$progressbar1.PerformStep()
}

#Enable the button so we can click it again
$this.Enabled = $true
$buttonCancelProcess.Enabled = $false
}
Attachments
form_UI.PNG
form_UI.PNG (11.09 KiB) Viewed 2563 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Responsive loop progress bar - sending me loopy

Post by jvierra »

If you keep clearing the progress bar the loop will never exit.
The rules of responsive forms say avoid processing in a loop while in an event.

If you have a job with multiple steps then run it as a job and use the JobTracker to manage the job.
User avatar
CI_Netops
Posts: 13
Last visit: Tue Nov 10, 2020 9:24 am

Re: Responsive loop progress bar - sending me loopy

Post by CI_Netops »

had a feeling you were going to say about the job tracker............something else I cant for some reason get my head around...i'll have a another good read up and see what I can do
User avatar
MarvelManiac
Posts: 63
Last visit: Thu Sep 13, 2018 3:40 pm

Re: Responsive loop progress bar - sending me loopy

Post by MarvelManiac »

Here is a breakdown for you that should help at least start wrapping your head around Jobs. It took me over a year and I'm still probably not doing it the most efficient way.
TestJobToSendOut.psf
(26.62 KiB) Downloaded 260 times
User avatar
CI_Netops
Posts: 13
Last visit: Tue Nov 10, 2020 9:24 am

Re: Responsive loop progress bar - sending me loopy

Post by CI_Netops »

excellent thank you for this
This topic is 6 years and 1 month old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked