KyleB

Calling a variable within another function

6 posts in this topic

I'm creating a script to create a new user and log into ts every time, I had it working but when i started simplifying my code into functions so i could separate them while testing, It couldn't find the variable. I'm just wondering if there is a way to take that variable from the other function.

 

LaunchSEQ ()
NameGen ()
JoinSEQ ()

Func NameGen ()
Local $arr[26] = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot","Golf","Hotel","India","Juliet","Kilo","Lima","Mike","November","Oscar","Papa","Quebec","Romeo","Sierra","Tango","Uniform","Victor","Whisky","X-Ray","Yankee","Zulu"]
   $i = Random(1, 26, 1)
   $name = $arr[$i] & "|Burns"
Send($name)
EndFunc

Func JoinSEQ ()
send("{ENTER}")
Send("^s")
Sleep(250)
Send("{TAB}")
Sleep(250)
Send("^a")
Sleep(250)
Send($name)
sleep(250)
send("{ENTER}")
EndFunc

Error is located at the bottom regarding the variable "$name"

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I don't see the error you reference, but if you need $name to be available to the entire script, the declare it at the top as Global. If this function is going to return that variable for use in a subsequent function, use Return instead (see help file for both).

Edited by JLogan3o13

When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

 

It says "Error: Variable used without being declared.", while i have declared it above it, just within another function.

   $name = $arr[$i] & "|Burns"
Send($name)
EndFunc
Sleep(250)
Send($name)
sleep(250)
send("{ENTER}")
EndFunc
Edited by KyleB

Share this post


Link to post
Share on other sites

Yes, that is the code - I thought you were posting the actual error you're receiving. That will help us a great deal.


When you're dead, you don't know you're dead - it's only difficult for those that know you. It's the same way when you're stupid...

My Scripts: SCCM UDFInclude Source with Compiled Script, Windows Firewall UDF

Share this post


Link to post
Share on other sites

Fixed it, thanks

Share this post


Link to post
Share on other sites
On 11/11/2016 at 1:46 PM, KyleB said:

Fixed it, thanks

It's always helpful to the forum community if you share how you resolved it.   Was it the because your random function upper and lower limits were wrong (zero-indexed array...0 to 25 instead of 1 to 26)?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now