Variables in a Wizard-Template form

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
ewilhelm009
Posts: 7
Joined: Fri May 15, 2020 7:21 am

Variables in a Wizard-Template form

Post by ewilhelm009 »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: PowerShell Studio 2020, Version 5.7.179
32 or 64 bit version of product: 64bit
Operating system: Windows 10 1809
32 or 64 bit OS: 64bit

*** Please add details and screenshots as needed below. ***

DO NOT POST LICENSES, KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM

I have a button that contains a variable that is declared ($variable = $textbox1.text) when it is pushed. I found that "all references" are found within the code block of that button. So even if that variable is declared there, when I run code later on in another button, it says the value is null. Are variables only used/referenced within the code block they're declared in?

I just don't know if these things should be in Globals.ps1 so that they can be referenced anywhere in the script. This is more of a question on understanding where I should be declaring variables that are needed by the entire script instead of isolating it to one button click event. Which would bring me to my next question, if $variable = $textbox1.text when is that variable declared? If I type "dog" in the text box, when does $variable = "dog"? or does $variable = $textbox1.text with each letter until I click away from the box?

Just trying to understand the logic with the software so I can do things right the first time. I'm still kinda learning PowerShell Studio

User avatar
brittneyr
Site Admin
Posts: 500
Joined: Thu Jun 01, 2017 7:20 am

Re: Variables in a Wizard-Template form

Post by brittneyr »

This has to do with scopes. The scope of an object is the region of the program in which it is accessible (i.e where you can call that object). All objects have a scope that defines where the name of the object can be used to refer to it. Your variables should be declared where it makes sense for them to be - where are you going to use them?

You may find the following helpful:
https://docs.microsoft.com/en-us/powers ... dfrom=MSDN
https://www.sapien.com/blog/2015/09/09/ ... l-gui-app/
https://www.sapien.com/blog/2013/04/10/ ... revisited/
https://www.sapien.com/blog/2013/03/06/ ... ing-rules/
Brittney Ryn
SAPIEN Technologies, Inc.

ewilhelm009
Posts: 7
Joined: Fri May 15, 2020 7:21 am

Re: Variables in a Wizard-Template form

Post by ewilhelm009 »

I will do some more reading with the links you provided. For now I have just copy/pasted the variables where I needed them to be down the line so the script will work in the meantime as I learn more. Thank you

Locked