A question about functions...

Author Message
struttshumming

  • Total Posts : 8
  • Scores: 0
  • Reward points : 0
  • Joined: 3/14/2008
  • Status: offline
A question about functions... Wednesday, September 24, 2008 10:52 PM (permalink)
0
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?
 
 
#1
    dm_4ever

    • Total Posts : 3687
    • Scores: 82
    • Reward points : 0
    • Joined: 6/29/2006
    • Location: Orange County, California
    • Status: offline
    RE: A question about functions... Thursday, September 25, 2008 3:09 AM (permalink)
    0
    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
     
    #2
      struttshumming

      • Total Posts : 8
      • Scores: 0
      • Reward points : 0
      • Joined: 3/14/2008
      • Status: offline
      RE: A question about functions... Thursday, October 09, 2008 5:27 AM (permalink)
      0
      cool, thanks for letting me know:)
       
      #3

        Online Bookmarks Sharing: Share/Bookmark

        Jump to:

        Current active users

        There are 0 members and 1 guests.

        Icon Legend and Permission

        • 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
        • Read Message
        • Post New Thread
        • Reply to message
        • Post New Poll
        • Submit Vote
        • Post reward post
        • Delete my own posts
        • Delete my own threads
        • Rate post

        2000-2012 ASPPlayground.NET Forum Version 3.9