none
Calling a global variable when running one script in another. RRS feed

  • Question

  • Hey guys, I am having some complications with one of my scripts. He is what I am trying to do. Run script "A" and set a value to variable "1" then have script A call script "B" and output that variable. This script is actually a set of forms, I just need the variable from the first script to display in the second.

    In script A

    $Global:Variable1 = $textbox.text   //user input

    In script B

    $label.text = $Global:Variable1

    Script A calls script B via an $Button.add_click ({pwershell.exe ..\file})

    The issue I am having is that the variable will not display when the script B is called by script A. However when I run Script B after running script A, the variable is present and displays properly. I can get it to properly display and run in all functions, its just when the other script is called it wont display.

    Unfortunately I can not post the whole script here, it is on another separate system so I hope I explained it correctly. Thanks in advance.

    Monday, April 18, 2016 6:01 PM

Answers

  • Ok since you are of no help. I have fixed my issue. I simply created a function out of the second script so it would have access to the variable. problem fixed.

    ohh and simpler way of saying that you need a better explanation of what I am doing is saying "can you please explain a little better on how you are setting your variable?" Not all of us have the ability to drop a script on here.

    • Marked as answer by Richardlaw Monday, April 18, 2016 7:47 PM
    Monday, April 18, 2016 7:47 PM

All replies

  • There is no way for us to guess at what you are doing.  You are clearly NOT setting the variable correctly.


    \_(ツ)_/

    Monday, April 18, 2016 6:12 PM
  • Ok since you are of no help. I have fixed my issue. I simply created a function out of the second script so it would have access to the variable. problem fixed.

    ohh and simpler way of saying that you need a better explanation of what I am doing is saying "can you please explain a little better on how you are setting your variable?" Not all of us have the ability to drop a script on here.

    • Marked as answer by Richardlaw Monday, April 18, 2016 7:47 PM
    Monday, April 18, 2016 7:47 PM
  • I see this a lot. You made a mistake.  You cannot see the mistake so you keep changing things until you get around it.  Next you bite everyone who tried to help you.

    We cannot see what you are doing and there is no way to guess at your issue,  Your fix is not supported by you explanation.

    Most of us have been scripting for years and many of us have advanced degrees and certification in programming so your ranting just seems silly.

    I am glad you chased away your issue. It is too bad that you didn't learn anything and that this thread is of no help to anyone who may find it.

    Thank you for wasting my time.


    \_(ツ)_/

    Monday, April 18, 2016 8:04 PM