Folks:
New to PS studio Gui. I am trying to pass variable\parameter to another event. For example i have Two button, Hello and World with label. Now when i click on Hello button, its shows Hello in label (as attach shows). Now i want to take Hello variable to world event and when click world button, should shows Hello world. I am not able to pass variable hello to world event. just need you folks help to understand...thanks for your help in advance.
passing variable to another event
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.
Re: passing variable to another event
$form1_Load={
#TODO: Initialize Form Controls here
}
$buttonHello_Click={
#TODO: Place custom script here
$hello = "Saying Hello "
$lbl.Text= $hello
}
$lbl_Click={
#TODO: Place custom script here
}
$buttonWorld_Click={
#TODO: Place custom script here
$world = "World"
$lbl.Text = $hello
}
#TODO: Initialize Form Controls here
}
$buttonHello_Click={
#TODO: Place custom script here
$hello = "Saying Hello "
$lbl.Text= $hello
}
$lbl_Click={
#TODO: Place custom script here
}
$buttonWorld_Click={
#TODO: Place custom script here
$world = "World"
$lbl.Text = $hello
}
Re: passing variable to another event
Simple - just add then up.
Code: Select all
$buttonWorld_Click={
#TODO: Place custom script here
$world = "World"
$lbl.Text += $world
}
Re: passing variable to another event
thx for your quick respond.
My goal here is how to pass variable from one event to different, showing in txtbox or label is to just show...
I am creating Azure admin tool, so if admin will click verify button, it does some stuff and create variable. This variable i want to be available to different events to call if another button press.
My goal here is how to pass variable from one event to different, showing in txtbox or label is to just show...
I am creating Azure admin tool, so if admin will click verify button, it does some stuff and create variable. This variable i want to be available to different events to call if another button press.
Re: passing variable to another event
You cannot pass variables between events. The system owns the events and handles all parameters.
To easily share data in a form you can save the data in a control or save it is a script scope variable.
To easily share data in a form you can save the data in a control or save it is a script scope variable.
Re: passing variable to another event
"To easily share data in a form you can save the data in a control or save it is a script scope variable"
any example you could share?
down below i would like to pass $ObjectId variable from $buttonHello to $buttonWorld and run $Results command
===============================================
$buttonHello_Click={
#TODO: Place custom script here
$ObjectId = $(Get-AzureADUser -Filter "UserPrincipalName eq '$EmpsUPN'").ObjectId
$textbox1.Text= $ObjectId
}
$buttonWorld_Click={
#TODO: Place custom script here
$world = "World"
$Results= get-AzureADUserManager -ObjectId $ObjectId -RefObjectId "test1"
$textbox1.Text += $world
}
===========================================
any example you could share?
down below i would like to pass $ObjectId variable from $buttonHello to $buttonWorld and run $Results command
===============================================
$buttonHello_Click={
#TODO: Place custom script here
$ObjectId = $(Get-AzureADUser -Filter "UserPrincipalName eq '$EmpsUPN'").ObjectId
$textbox1.Text= $ObjectId
}
$buttonWorld_Click={
#TODO: Place custom script here
$world = "World"
$Results= get-AzureADUserManager -ObjectId $ObjectId -RefObjectId "test1"
$textbox1.Text += $world
}
===========================================
Re: passing variable to another event
Here is the correct way to code something like this in Forms.
Avoid over-quoting things and avoid using syntactic constructs without understanding what they do.
Code: Select all
$buttonHello_Click={
$textbox1.Text = (Get-AzureADUser -Filter "UserPrincipalName eq '$EmpsUPN'").ObjectId
}
$buttonWorld_Click={
$results = get-AzureADUserManager -ObjectId $textbox1.Text -RefObjectId test1
}
Re: passing variable to another event
those are are good points but i am just testing variables with events.
So in my real gui what i am trying to build when button verification click, it runs some command in Azure and shows in label. these commands get three values in three different variables. Now, if user click another button to execute, three values variables used in this event to execute some other commands.
So, questions would be whatif more then one variables needs to pass to events?
really appreciate your help..thanks
So in my real gui what i am trying to build when button verification click, it runs some command in Azure and shows in label. these commands get three values in three different variables. Now, if user click another button to execute, three values variables used in this event to execute some other commands.
So, questions would be whatif more then one variables needs to pass to events?
really appreciate your help..thanks
Re: passing variable to another event
I have absolutely no idea what you are trying to ask. You need to learn enough PowerShell to be able to ask a basic question.
To persist variables in an event use scoping to set the scope to "script" or "global" and the variables will be available in any other event.
help about_scopes
To persist variables in an event use scoping to set the scope to "script" or "global" and the variables will be available in any other event.
help about_scopes