Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VFP equivalent to EVAL() ???

Status
Not open for further replies.

mp9

Programmer
Sep 27, 2002
1,379
GB
Is there a VFP equivalent to the EVAL() function in VBA?

For those unfamiliar with EVAL(), it can be used to evaluate an expression that results in a text string or a numeric value. Amongst other things, it can be used to evaluate/construct function names on the fly, e.g.
Code:
    Dim intI As Integer

    For intI = 1 To 50
        Eval("A" & intI & "()")
    Next intI
in VBA runs the functions A1, A2, A3, etc, sequentially.

I need to do something similar in VFP 5.0a but can't find a similar function. Anyone have any ideas?
 
There is EVALUATE(), which can also be abbreviated to EVAL():
Code:
? Evaluate("myfunc()")

Function myfunc()
  Return "hello"
EndFunc

The function must be in scope (known by being in the same PRG or by SET PROCEDURE TO or being a native function call).

In your case perhaps:
Code:
set procedure to a_functions.prg additive && containing a1() to a50()
Local liCount 
For liCount = 1 To 50
   Eval("A" +transform(liCount)+ "()")
Next iCount

Then there is Execscript(), which could be called once with all the calls in one string:

Code:
set procedure to a_functions.prg additive && containing a1() to a50()
Local liCount , lcCode
lcCode = ""
For liCount = 1 To 50
   lcCode = lcCode+ "A" +transform(liCount)+ "()"+chr(13)+chr(10)
Next liCount
Execscript(lcCode)

Bye, Olaf.
 
You could also use the macro expansion operator &:

Code:
Local intI

For intI = 1 To 50
  lcFunc = "A" + transform(intI) + "()"
  &lcFunc
Next intI

Fox doesn't let us concatenate the string "A" and the integer intI so it looks a little more ungainly than VB.

Geoff Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top