Page 1 of 1

Returning ChildForm values in MainForm variable!

Posted: Tue Apr 16, 2019 8:32 pm
by Taras_ua
NEED HELP!!!!


Work in PS studio 2017

Code: Select all

$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)
}
}

Re: Returning ChildForm values in MainForm variable!

Posted: Tue Apr 16, 2019 9:04 pm
by jvierra
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

Re: Returning ChildForm values in MainForm variable!

Posted: Wed Apr 17, 2019 7:39 am
by davidc
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

Re: Returning ChildForm values in MainForm variable!

Posted: Fri Apr 19, 2019 3:07 am
by Taras_ua
mr. jvierra
PowerShell Studio automatically generates return variables for the child form controls. And I use it/

https://info.sapien.com/index.php/guis/ ... sing-forms

Re: Returning ChildForm values in MainForm variable!

Posted: Fri Apr 19, 2019 3:48 am
by jvierra
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.