Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Returning a String from a function
#7
Okay, I'm still not quite there... apologies! :-)

I'm having strange problems when I declare functions in advance. Code which would previously compile starts giving 'undefined label' compilation errors once I declare a function.

For instance, this segment of a high score routine compiles okay:
Code:
'table arrays
dim hsScore(10) as UINTEGER
dim hsName(10) as STRING

'displays the table and prompts the user to enter a name
sub hsEnterName(hsPos as UBYTE)
    
    'get the user to enter a name
    dim hsNewName as STRING
    hsNewName = "NOBODY"
    
    'assign the name to the array
    hsName(hsPos) = hsNewName
    
end sub

function hsGetName(hsY as UBYTE) as STRING
    return "TEST"
end function

However, I can't call hsGetName unless I declare it, so I changed the code to include a line for that:
Code:
'table arrays
dim hsScore(10) as UINTEGER
dim hsName(10) as STRING

declare function hsGetName(hsY as UBYTE) as STRING

'displays the table and prompts the user to enter a name
sub hsEnterName(hsPos as UBYTE)
    
    'get the user to enter a name
    dim hsNewName as STRING
    hsNewName = "NOBODY"
    
    'assign the name to the array
    hsName(hsPos) = hsNewName
    
end sub

function hsGetName(hsY as UBYTE) as STRING
    return "TEST"
end function

Now when I try to compile I get this:
Code:
test.bas:51: Error: Undefined label '_hsName'

The longer piece of code that this comes from generates similar but slightly different compilation errors (sometimes the label names are not ones that I've used in the code), and the line numbers reported do not always point to relevant lines of code (e.g. sometimes they point to lines which only have comments on them).

Am I missing something in the declare statement? This is still with 1.2.7, btw.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)