Page 1 of 1

Responsive Forms

Posted: Tue Oct 09, 2018 6:24 am
by Genx13
I'm having trouble wrapping my head around the responsive forms with the examples from the articles below. Does anyone have a simple form that copies files or something they could share using this method. I really think I just need to see an example of a working script that I can dissect.

https://www.sapien.com/blog/2011/07/15/primalforms-2011-creating-responsive-loops
https://info.sapien.com/index.php/guis/gui-advanced-tips/creating-responsive-loops

Re: Responsive Forms

Posted: Tue Oct 09, 2018 8:46 am
by jvierra
The "Start Job" custom control set is also an example. Just place it on a new form and run it. Look at the code and notice what it is doing.

Re: Responsive Forms

Posted: Thu Oct 11, 2018 12:38 pm
by Genx13
So I looked again at the "Button-Start Job" code along with a longer look at the Creating Responsive Forms and Responsive Loops.

I think It's starting to sink in a bit I'm still not getting something. I used your "Demo-JobChildForm" as a template, I have a main form with one button that opens the child form below. Using the code from the "Creating Responsive Forms" I can get the ping to run and the progress bar to fill. I edited that to try doing a copy-Item but I can't figure out how to get the progress bar to work with the $count variable.

I'm sure I'm doing something wrong i just can't see where. My best guess is I'm doing something wrong with the $UpdateScript code. Also the files do copy the bar just doesn't reflect that.
  1. param
  2. (
  3.     $JobName = 'MyJob'
  4. )
  5.  
  6. $JobScript =
  7. {
  8.     $Source = 'C:\Users\tuser\Desktop'
  9.     $Destination = 'C:\Users\tuser\Documents\TestCopy'
  10.     [int]$Count = $Source.count
  11.    
  12.     for ($i = 0; $i -lt "$($Count)"; $i++)
  13.     {
  14.         #Do some work
  15.         Copy-Item -Path $Source -Destination $Destination -Recurse
  16.         #Start-Sleep -Milliseconds 100
  17.         #Output Progress
  18.         $i + 1
  19.     }
  20. }
  21.  
  22. $UpdateScript =
  23. {
  24.     Param ($Job)
  25.     $results = Receive-Job -Job $Job | Select-Object -Last 1
  26.    
  27.     if ($results -is [int])
  28.     {
  29.         $PBar_Copy.Value = $results
  30.     }
  31. }
  32.  
  33. $CompletedScript =
  34. {
  35.     Param ($Job, $Count)
  36.     $PBar_Copy.Value = $Count
  37. }
  38.  
  39. $formChildForm_Load={
  40.     #TODO: Place custom script here
  41.     Add-JobTracker -Name $JobName -JobScript $jobscript -UpdateScript $updatescript -CompletedScript $completedscript
  42. }

Re: Responsive Forms

Posted: Thu Oct 11, 2018 12:50 pm
by jvierra
Copy-Item has no output and will block the loop until it is done. The progress bar will not work here.

Re: Responsive Forms

Posted: Thu Oct 11, 2018 12:57 pm
by Genx13
Is there any other way to show the progress during a file copy? Would a Marquee Progress bar work?

Do you have any recommendations for show progress on a file copy, that could show a percentage done or anything?

Would Copy-WithProgress work better?

Re: Responsive Forms

Posted: Thu Oct 11, 2018 1:31 pm
by jvierra
No. There is no progress for any blocking command.