Use a form for user input but show output on console

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 8 years and 8 months 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
yobyot
Posts: 40
Last visit: Tue Jun 02, 2020 3:09 pm

Use a form for user input but show output on console

Post by yobyot »

I want to create a single form script that accepts user input but displays the output on the PowerShell console.

I don't understand if I can create PowerShell console or not -- this link (https://www.sapien.com/blog/2014/12/15/display-output-in-a-gui-application-copy/) says there isn't.

But if I open a second (child) form with a multi-line textbox on that form, I can't seem to display output line by line. The status info I need to display to user appears after the script finished.

I don't need or want the complexity of running that code in jobs, as recommended here: https://www.sapien.com/blog/2012/05/16/powershell-studio-creating-responsive-forms/

What's the simplest way to allow a user to select items on a form, then show the user the processed output of that selection as it's processed based on the input selections?

I REALLY miss the PS console, which would be perfectly fine. :-)
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Use a form for user input but show output on console

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, yobyot.

Did you remember to include the following?
  • 1. Product, version and build (e.g. Product: PrimalScript 2014, Version & Build: 7.0.46. Version and build information can be found in the product's About box accessed by clicking the blue icon with the 'i' in the upper right hand corner of the ribbon.)
    2. Specify if you are running a 32 or 64 bit version
    3. Specify your operating system and if it is 32 or 64 bit.
    4. Attach a screenshot if your issue can be seen on the screen
    5. Attach a zip file if you have multiple files (crash reports, log entries, etc.) related to your issue.
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Use a form for user input but show output on console

Post by davidc »

Hello yobyot,

When calling a GUI form or (even a second GUI form from another) it is displayed "Modal" fashion which means that the script will not continue until the form is closed. In other words, the first GUI will "freeze" until the second child form closes.

As for the console output, you can still run output commands from the GUI script. I.e. Write-Host or Out-Default. These outputs will be displayed by the console, if the GUI script in ran within that environment.

What I would recommend is having an OK or Submit button and within that button's click event processes the data and output as you would normally and close the form if necessary.

David
David
SAPIEN Technologies, Inc.
User avatar
yobyot
Posts: 40
Last visit: Tue Jun 02, 2020 3:09 pm

Re: Use a form for user input but show output on console

Post by yobyot »

Thanks.

My current attempt works like this:

1). User makes selections on main form
2). Main form is closed and child form is called via call_formaname_psf
3). In child form, I am attempting to process user's selections in a switch statement that processes the array passed from the main form
4). After each item is processed, I am attempting to update the child form's single textbox with $textbox1.appendtext("String").

My problem is that step 4 doesn't produce any updated info in the list box until the switch statement ends.

I simply want to imitate what would happen on the console via write-host statements, but put them in a list box after each result is calculated.

I've tried lots of things. .Invoke() on the child form load script and .Update() on the listbox in various places. If I can just find a way to display the listbox on the form at the beginning of my logical processing and then eachtime I .appendtext, my problem is solved.

Appreciate the help. I am enjoying PSS 15 and have been successful at much of this -- creating a multi-form project, having the main form pass parameters to the child form and other aspects of this smallish app. But getting that child form to display updated text as I process items has eluded me so far.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Use a form for user input but show output on console

Post by davidc »

You will benefit from reading (if you haven't already) the following article:

https://www.sapien.com/blog/2013/10/01/powershell-studio-passing-and-returning-values-using-forms/

When you are in an intensive loop the GUI will not be able to update or respond. See: https://www.sapien.com/blog/2011/07/15/primalforms-2011-creating-responsive-loops/

I'm not sure if you are using a textbox or a listbox. In either case, you can use the control's Refresh method to force it to redraw. Alternatively you can use the DoEvents method mentioned in the article above.

David
David
SAPIEN Technologies, Inc.
User avatar
yobyot
Posts: 40
Last visit: Tue Jun 02, 2020 3:09 pm

Re: Use a form for user input but show output on console

Post by yobyot »

Thanks.

I've read both of these but they weren't much help.

My big issue is getting the child form up before the loop begins and then updating it as results come in during the loop.

I had no problems passing parameters from the main form to the child form (the first link). But the second link doesn't seem applicable to a listbox. BTW, I tried both a listbox and a testbox with multiline enabled.
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Use a form for user input but show output on console

Post by davidc »

If you can, please zip and attach the project to this topic. It is difficult to determine the issue without seeing the code.

David
David
SAPIEN Technologies, Inc.
User avatar
yobyot
Posts: 40
Last visit: Tue Jun 02, 2020 3:09 pm

Re: Use a form for user input but show output on console

Post by yobyot »

davidc wrote:If you can, please zip and attach the project to this topic. It is difficult to determine the issue without seeing the code.

David
I appreciate your willingness to look at the code and help out a newbie -- but is there a way I can email a zip to you? I'd prefer not to have this public, since it contains interactions with AWS and has (temporary access keys in it).

Thanks again.

Alex
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Use a form for user input but show output on console

Post by davidc »

In that case just zip and email the file to support@sapien.com.

David
David
SAPIEN Technologies, Inc.
User avatar
Alexander Riedel
Posts: 8479
Last visit: Thu Mar 28, 2024 9:29 am
Answers: 19
Been upvoted: 37 times

Re: Use a form for user input but show output on console

Post by Alexander Riedel »

This really is not a topic that presents a support issue with a trial version. This is more an question related to how to use GUIs with PowerShell. I moved this thread to the corresponding forum.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 8 years and 8 months 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