Jump to content
Sign in to follow this  

passing an array to a function

Recommended Posts


I want to read some characters from an array and return an array with those characters. Here is the function:

func getword($array, byref $index)
    while $array[$index]=$null
    if $array[$index]=$termstr then
        return $null
        dim $word[1]
        while iswordchar($array[$index])

I'm passing it an array in the last line of this code block:


;adds the terminal element


But when I run, I get this message:

while $array[$index]=$null

while $array^ ERROR

Error: Subscript used with non-Array variable.

But I declared $stringarray as an array by using stringsplit(). I don't understand why the function isn't accepting it as an array.

Share this post

Link to post
Share on other sites

Here is your code cut down to something that will show the issue and will run by itself:

$fullstring = "stringstringstring"
$stringarray = StringSplit($fullstring, "")

Global $null = 1
Global $place = 1
Global $word = getword($stringarray, $place)

Func getword($array, ByRef $index)
    While $array[$index] = $null
        $index = $index + 1
I'm not sure if Global is the "proper" way to solve your problem, but it works.


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
Sign in to follow this