Login | |
|
 |
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?
|
|
| |
|
|
|
 |
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
|
|
| |
|
|
|
|
|