Product, version and build: Powershell studio 2018 / Powershell version 5.0.10586.117
32 or 64 bit version of product: 64-bit
Operating system: Win-7 Pro
32 or 64 bit OS: 64-bit
Hi.
I am trying to enable some functions i've defined in a PSM1 module that is loaded with a Posh GUI Form to write back to a text box on the main form. But i am unable to do so.
I can write to this text box from the code in the .PSF file that i am creating a 32-bit EXE from; however i am unable to get a function that loaded via a PSM1, when the form loads with an import-module, to be able to write to the form's text-box (for function status updates).
FYI - this product is awesome.
Thanks for any help!
-frank
trying to get a function loaded from a PSM1 to write to a PSF-defined text box
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.
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.
- fvenezia65
- Posts: 8
- Last visit: Wed Feb 14, 2024 9:44 am
Re: trying to get a function loaded from a PSM1 to write to a PSF-defined text box
[TOPIC MOVED TO POWERSHELL GUIS FORUM]
If you can provide an example, we will be able to assist you further. Typically, you want to use the Out-String to set the Text of the textbox control.
I recommend looking at the "TextBox - Get Process" control set (located in Tools Panel->Control Sets tab).
More info on TextBox control:
https://info.sapien.com/index.php/guis/gui-controls/spotlight-on-the-textbox-control
If you can provide an example, we will be able to assist you further. Typically, you want to use the Out-String to set the Text of the textbox control.
Code: Select all
$textBox1.Text = Get-Process | Out-String
More info on TextBox control:
https://info.sapien.com/index.php/guis/gui-controls/spotlight-on-the-textbox-control
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
- fvenezia65
- Posts: 8
- Last visit: Wed Feb 14, 2024 9:44 am
Re: trying to get a function loaded from a PSM1 to write to a PSF-defined text box
Hi, David.
Thanks for the reply.
I believe my issue is one of variable-scope.
I *am* able to update the textbox from the main .PSF compiled EXE GUI.
my issue occurs in a function defined in a PSM1 module that is loaded in the PSF.
when i call any function in that PSM1, i am unable to write back into that textbox from the main .PSF routine.
a .psf defines the textbox and imports a .PSM1 with our functions.
when we call one of the imported-functions, it generates an error and doesn't update the text-field, when we try to write to that textbox defined in the .PSF.
Thanks for any help/thoughts on this one.
-frank
Thanks for the reply.
I believe my issue is one of variable-scope.
I *am* able to update the textbox from the main .PSF compiled EXE GUI.
my issue occurs in a function defined in a PSM1 module that is loaded in the PSF.
when i call any function in that PSM1, i am unable to write back into that textbox from the main .PSF routine.
a .psf defines the textbox and imports a .PSM1 with our functions.
Code: Select all
$richtextbox1.Text = "Loading the NwHS-NOC-Utils PoSh Module."
Import-Module -Force "path\PowerShell-scripts\NWHS-NOC-Utils.psm1"
Code: Select all
if ($OnScreen)
{
"$LogTime `t $EventToLog"
$global:richtextbox1.Text = "$LogTime `t $EventToLog"
}
-frank
Re: trying to get a function loaded from a PSM1 to write to a PSF-defined text box
If the variable is part of a module (and the psf is separate from the module) then the module will have to export the variable. You have to do this because modules have their own variable scope.
Typically, if you want to reference a variable across functions or form events, you will need to specify the script scope for that variable:
Typically, if you want to reference a variable across functions or form events, you will need to specify the script scope for that variable:
Code: Select all
$script:variable = 'value'
David
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.