responsive forms

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 10 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
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

responsive forms

Post by mmmoi5 »

Hello everyone,

I have a PowerShell studio Project that performs certain Exchange and SQL tasks.
It Works fine with one flaw and I was hoping someone would shed som light on the matter.

Every time a button is pressed the entire GUI is locked in "Not Responding".
I read on this forum that responsive forms are the key but I cannot seem to get it to work.

An example:
One of the buttons test a server connection to the SQL server.

###################

$buttonTestConnection_Click = {
$richtextbox1.AppendText("Testing connection to the specified SQL server. `r `n")
$conTestServer = ($textbox1.Text)
$Error.Clear()
$connectionString = "Data Source=$conTestServer;Integrated Security=true;Initial Catalog=master;Connect Timeout=3;"
$sqlConn = new-object ("Data.SqlClient.SqlConnection") $connectionString
$sqlConn.Open()
if ($sqlConn.State -eq "closed")
{
$richtextbox1.AppendText("Connection to $conTestServer FAILED. `r `n")
return
}
else
{
$sqlConn.Close();
$richtextbox1.AppendText("Connecting to $conTestServer was successful. `r `n")
}
}
###################

If I use the "Start-Job" button, how can I make it append to the richtextbox based on the if / else result?

Other functions also include a
foreach($entry in $entries]
{
do something
}
else
{
do something else
}

how do I account for the many results that arise in a start-job while also getting results back that I either feed to another array or append certain text to a listbox?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: responsive forms

Post by jvierra »

Please read the article on responsive forms very carefully as it gives a detailed explanation of how to use these tools.

Download and run the sample for responsive forms and review it until you understand how it works.
User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: responsive forms

Post by mmmoi5 »

I have read and seen the sample regarding the $computer yes or no scenario
I have not become the least bit wiser as to how one would accommodate a scenario such as the one I presented earlier.

I will read it again in hope of wisdom peeking through.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: responsive forms

Post by jvierra »

Don't just read it quickly. Read it a do all of the examples. Download the sample form and run it. Run it under the debugger to see what happens in each event.

This article: http://info.sapien.com/index.php/guis/g ... sive-forms

You can download the sample Job Progress bar form at the bottom of the page.

Be sure to unblock thee zip file then extract. Open with PSS. It is a PFF file but PSS will convert it. Save it as a PSF and run it to see what happens.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: responsive forms

Post by jvierra »

You can also read the following to understand how to create responsive loops.

http://info.sapien.com/index.php/guis/g ... sive-loops
User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: responsive forms

Post by mmmoi5 »

thank you for Your information, I have now read all the articles you referred to.

I understand the Logic behind the jobscript, completedscript and updatescript, but I still cannot see how that addresses my question, how does one return the multiple variables back from the job ( to publish, append or manipulate).
If the scriptblock populates an X amount of variables, how do I Return them.


Example
How do I Return both $conclusion and $response in the example below


#Create a New Job using the Job Tracker
Add-JobTracker -Name "JobName" `
-JobScript {
for($i = 0; $i -lt 100; $i++)
{
Do something #1
if ($? -like "True")
{$conclusion = "PASS"}else{$conclusion = "fail"}

Do something #2
if ($? -like "True")
{$response = "PASS"}else{$response = "fail"}

#Output Progress
$i + 1
}
}`
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: responsive forms

Post by jvierra »

You would create and return objects or object collections just like any other function or script would return things.
User avatar
mmmoi5
Posts: 14
Last visit: Wed Dec 19, 2018 3:29 am

Re: responsive forms

Post by mmmoi5 »

It must be me, I have started With PowerShell and Powershell Studio only 3 weeks ago.
Calling my $response and $conclusion variables to append their values to the richtextbox is not working for me at all.

The $results = receive-job -job $job does not Return my variables.
I can append the entire $results but not the $resopnse and $conclusion

I will attempt to address this issue on a PowerShell forum maybe someone has experienced my beginner delima.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: responsive forms

Post by jvierra »

You have to return the variables from a function, script or script block. Your script block is not returning anything.

For get about forms. Create and run a job at a CLI prompt. Read the help for "Start-Job" and look at the examples. After you understand how a job works then you can design a script block that returns data in a usable way.

You can design and build your job script in PS CLI and it will run correctly in a form. You will also learn how PS Jobs work.

Until you learn how PowerShell works forms will only be very hard for you to design and build. I always start by testing complex code in PS CLI until it behaves correctly then I port it into the form. If a job does not run as needed in CLI then it will be useless in a form.
User avatar
angelofstealth
Posts: 69
Last visit: Wed Sep 28, 2022 10:04 am

Re: responsive forms

Post by angelofstealth »

Hello mmmoi5 ,
I can feel your frustration and was in your situation a couple of weeks ago. jvierra is correct to review the forums/articles in regards to the jobtracker. What can't be answered is the logic that you want to apply to the form or order of operations. This was where I was having a hard time with the jobtracker and I had to read the article a few times and think how the order of operations was going to be and how the jobtracker would come to play into it. jvierra helped me a great deal to better understand the jobtracker, built in control. Based on reading the responses I think i understand what you are trying to do. jvierra provided me with a different code/form on listing the jobtracker per the article and i found that very useful. You cannot update the form within the $Jobscript. I have attached a form with what I think you are trying to do to help guide you.

jvierra: Hopefully based on our previous forum/question, i am coding/answering to your standard. Being honest, you helped me better understand it. Thanks again,
Attachments
SQLConnect.psf
(31.22 KiB) Downloaded 173 times
This topic is 6 years and 10 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