Jump to content

Recommended Posts

Posted

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
        $index=$index+1
    wend
    if $array[$index]=$termstr then
        return $null
    else
        dim $word[1]
        $word[0]=0
        while iswordchar($array[$index])
            $word[0]=$word[0]+1
            _arrayadd($word,$array[$index])
            $index=$index+1
        wend
    endif
endfunc

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

$size=filegetsize($path)
$handle=fileopen($path,0)
$fullstring=fileread($handle,$size)
fileclose($handle)
$stringarray=stringsplit($fullstring,"")

;adds the terminal element
$stringarray=_arrayadd($stringarray,$termstr)

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

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.
Posted

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
    WEnd
EndFunc
I'm not sure if Global is the "proper" way to solve your problem, but it works.

[size="1"][font="Arial"].[u].[/u][/font][/size]

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...