Search code examples
arraysvbscriptolevisual-foxprofoxpro

How do I return an array from a Visual FoxPro 9 OLEPUBLIC class?


As a newbie to FoxPro (but an old-hand at Clipper), I'm a bit at a loss to figure out how to return an array from the following OLEPUBLIC class. edit: I've modified the code belw to take into consideration the remarks made by @Stuart below.

DEFINE CLASS db AS CUSTOM OLEPUBLIC

    DIMENSION ada(1) && public scope for later return

    FUNCTION opendb( cpName )
        SET MULTILOCKS ON
        USE (cpName) EXCLUSIVE NOUPDATE
        = CURSORSETPROP("Buffering",5)
        RETURN ALIAS()
    ENDFUNC

    && etc

    FUNCTION getrecord( sAlias, nRecno )
        SELECT (sAlias)
        GOTO (nRecno)
        fc = FCOUNT()
        DIMENSION this.ada(fc)
        FOR i = 1 TO fc
            STORE CURVAL(FIELD(i)) to THIS.ada(i)
        ENDFOR
        RETURN @THIS.ada
    ENDFUNC
ENDDEFINE

Given the following bit of VBScript, I can open the file fine. What I can't seem to do is get back anything more useful than an error message.

set sp = createobject("sloop.db")
al = sp.opendb("p:\testing\sloop\patient.dbf")
wscript.echo sp.getrecord(al,1)

This is the error message:

c:\temp\foo.vbs(3, 1) sloop.db sloop.db: .getrecord p:\testing\sloop\sloop.prg Error in line 41 Syntax error. 200

Line 41, as it turns out, is

      RETURN @THIS.ada

which is really weird as that's the syntax that Microsoft suggests. Any clues?


Solution

  • Try 'return @ada', but VFP arrays have never played nicely with other languages despite attempts to make them do so.