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.
-
Taras_ua
- Posts: 2
- Joined: Thu Mar 28, 2019 2:08 pm
Post
by Taras_ua » Tue Apr 16, 2019 8:32 pm
NEED HELP!!!!
Work in PS studio 2017
$buttonCallChildForm_Click={
if((Show-ChildForm_psf) -eq 'OK')
{
$LocAdmin = $ChildForm_SetAdmin
$LocPassword = $ChildForm_SetPass
$errorMsg = "admin - " + $LocAdmin + ", password= " + $LocPassword
$caption = "PassWord ERROR"
[System.Windows.Forms.MessageBox]::Show($errorMsg, $caption)
#Returning values and we see it!
}
#but in MainForm no changes
$buttonCheck1_MouseDown=[System.Windows.Forms.MouseEventHandler]{
$errorMsg = "admin - " + $LocAdmin + ", password= " + $LocPassword
$caption = "PassWord ERROR"
[System.Windows.Forms.MessageBox]::Show($errorMsg, $caption)
}
}
-
jvierra
- Posts: 14000
- Joined: Tue May 22, 2007 9:57 am
-
Contact:
Post
by jvierra » Tue Apr 16, 2019 9:04 pm
Setting a variable in an event only defines the variable in the event. YOU cannot retain the value. It works the same for a function. Variables defined in a function or set in a function do not exists after the function ends. This is tru or all PowerShell scripts.
To understand this read the following;
https://docs.microsoft.com/en-us/powers ... wershell-6
-
davidc
- Posts: 5913
- Joined: Thu Aug 18, 2011 4:56 am
Post
by davidc » Wed Apr 17, 2019 7:39 am
PowerShell Studio automatically generates return variables for the child form controls. It uses the following naming convention for the return variables:
$ChildFormName_ControlName
The easiest way to determine if the variable is correct is by hovering over it. If PowerShell Studio displays the type information, then you have to correct variable name. You can also use PowerShell Studio's PrimalSense. Press $ and the return variables will be included in the variable list.
Here is a related article (The function verbs used are outdated):
https://info.sapien.com/index.php/guis/ ... sing-forms
David
SAPIEN Technologies, Inc.
-
jvierra
- Posts: 14000
- Joined: Tue May 22, 2007 9:57 am
-
Contact:
Post
by jvierra » Fri Apr 19, 2019 3:48 am
Yes - I know that but that was not your original question. The variables defined in the child form are available in the calling form as defined but it you assign them to a new variable in an event then the new variable will not be available outside of the event. Just use the child defined variables. There is no need to redefine them.
You should not do this:
$LocAdmin = $ChildForm_SetAdmin
It is unnecessary and the new variable will not be visible to the whole form.