Define global variables

Source: Internet
Author: User

In ps2.0, the button can directly call the variables defined in the checkbox, as follows:

$ Checkbox#checkedchanged = {
# Todo: Place custom script here
If ($ checkbox1.checked) {$ A = 1}
Else {$ A = 0}

}

$ Button#click = {
# Todo: Place custom script here
Write-host $
}

When checkbox1 is selected, after you click the button1 button, $ A returns 1; When checkbox1 is not selected, after you click the button1 button, $ A returns 0

However, in ps3.0 and 4.0, no matter whether checkbox1 is selected or not, after you click the button1 button, $ A does not return a value. In other words, you cannot directly call the variables defined in the checkbox.

 

The solution is to define global variables as follows:

$ Global: a = 0

$ Checkbox#checkedchanged = {
# Todo: Place custom script here
If ($ checkbox1.checked) {$ Global: a = 1}
Else {$ Global: a = 0}
}

$ Button#click = {
# Todo: Place custom script here
Write-host $ Global: A # Write-host $ A has the same effect, as long as it is defined as a global variable under checkbox1.
}

When checkbox1 is selected, after you click the button1 button, $ A returns 1; When checkbox1 is not selected, after you click the button1 button, $ A returns 0

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.