Page 1 of 1

passing variable to another event

Posted: Tue Mar 24, 2020 9:45 am
by ausman
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.

Re: passing variable to another event

Posted: Tue Mar 24, 2020 9:46 am
by ausman
$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
}

Re: passing variable to another event

Posted: Tue Mar 24, 2020 1:38 pm
by jvierra
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

Posted: Tue Mar 24, 2020 2:00 pm
by ausman
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.

Re: passing variable to another event

Posted: Tue Mar 24, 2020 2:11 pm
by jvierra
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.

Re: passing variable to another event

Posted: Tue Mar 24, 2020 2:59 pm
by ausman
"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
}
===========================================

Re: passing variable to another event

Posted: Tue Mar 24, 2020 3:05 pm
by jvierra
Here is the correct way to code something like this in Forms.

Code: Select all

$buttonHello_Click={
    $textbox1.Text = (Get-AzureADUser -Filter "UserPrincipalName eq '$EmpsUPN'").ObjectId
}

$buttonWorld_Click={
    $results = get-AzureADUserManager -ObjectId $textbox1.Text -RefObjectId test1
}
Avoid over-quoting things and avoid using syntactic constructs without understanding what they do.

Re: passing variable to another event

Posted: Wed Mar 25, 2020 9:58 am
by ausman
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

Re: passing variable to another event

Posted: Wed Mar 25, 2020 10:06 am
by jvierra
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