views:

670

answers:

2

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?

A: 

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

Stuart Dunkeld
A: 

Your revised code works for me in VFP9SP2 - I had to build as an EXE but managed to access data from VBSCript.

This was my VBScript code:

set sp = createobject("stack1.db") ' Different project name
al = sp.opendb("C:\WORK\VFP\DATABASES\DATA\DATA.DBF")
arrData = sp.getrecord(al,1)
msgbox(arrData(1))
Stuart Dunkeld
I just realised that I was still using VFP6. It was my old machine that had v9. Embarrassment++
boost