Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


A question about functions...

 
Logged in as: Guest
arrSession:exec spGetSession 2,5,64540
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> Windows PowerShell >> A question about functions...
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 A question about functions... - 9/24/2008 9:52:27 PM   
  struttshumming

 

Posts: 8
Score: 0
Joined: 3/14/2008
Status: offline
Hi There,

I have been trying to put together a simple function that takes in 2 argumnets. I then want to split them into arrays and try to return a given element of each. here is my code:


$StrOne
= "1,2,3,4"

$StrTwo
= "A,B,C,D"
 

function
DoStuff
{
param ([string]$Numbers,[string]$Letters)
 

  $ArrNum = $Numbers.split(",")
  $ArrLet = $Letters.split(",")

  #write-host $ArrLet[0]

  write-host
$ArrNum[3]
 


}

 

DoStuff
($StrOne,$StrTwo)
 

But...i dont understand how it is returning both elements when (4 & A) when the letters array split is commented out.

Where have i gone wrong?
 
 
Post #: 1
 
 RE: A question about functions... - 9/25/2008 2:09:18 AM   
  dm_4ever


Posts: 2669
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Its due to the way you are passing the values...it is slightly different that you would with VBScript

$StrOne = "1,2,3,4"

$StrTwo = "A,B,C,D"


function DoStuff
{param ([string]$Numbers,[string]$Letters)

$ArrNum = $Numbers.split(",")
$ArrLet = $Letters.split(",")

#write-host $ArrLet[0]

write-host $ArrNum[3]



}


DoStuff $StrOne $StrTwo

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to struttshumming)
 
 
Post #: 2
 
 RE: A question about functions... - 10/9/2008 4:27:32 AM   
  struttshumming

 

Posts: 8
Score: 0
Joined: 3/14/2008
Status: offline
cool, thanks for letting me know:)

(in reply to dm_4ever)
 
 
Post #: 3
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> Windows PowerShell >> A question about functions... Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts