Passing form variable to a script to then return a result back to the form

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 7 years and 4 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
simon.briggs
Posts: 10
Last visit: Mon Feb 01, 2021 6:18 am

Passing form variable to a script to then return a result back to the form

Post by simon.briggs »

Product, version and build: PSS 2016 5.2.129
32 or 64 bit version of product: 64
Operating system: Win 7 Enterprise 64bit
PowerShell Version:5

I am trying to pass textbox.text to a script to run a command which will then return a result to the parent form. The command needs to be run by script because it does not return a result from the form. Having followed the passing parameters between forms blog post I have set up a similar script which doesn't rely on any variables being fetched from the parent but for the life of me cannot get this to pass to the script.
This is from the parent form
$buttonCloseFile_Click = {
Call-closesession_ps1 | Out-Host
#Write-Host "$closef"
}

This is from the script
if ((Call-MainForm_psf) -eq "ok")
{
$id = $MainForm_textbox2
openfiles /disconnect /s <fileserver> /ID "$id"
}

Another copy of the parent form opens when the button is pressed.
User avatar
simon.briggs
Posts: 10
Last visit: Mon Feb 01, 2021 6:18 am

Re: Passing form variable to a script to then return a result back to the form

Post by simon.briggs »

Update: Having realised that I can't use a variable to define a parameter I have changed to using script variables instead.

testing now to confirm that it is working but it looks to have resolved my issue.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: Passing form variable to a script to then return a result back to the form

Post by DevinL »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
DevinL
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Passing form variable to a script to then return a result back to the form

Post by jvierra »

$textbox2.Text = .\myscript.ps1 $textbox1.Text
This topic is 7 years and 4 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