?
Solved

Using UDFs in grids

Posted on 2014-10-19
3
Medium Priority
?
281 Views
Last Modified: 2014-10-19
I'm having a problem with a column in a grid, which I want to display the results of a UDF.

I've got this column defined in the .INIT() method as using

    .ControlSource = "inttohex(VAL(names.value),4)"

- where inttohex() is a UDF that converts an integer into a hexadecimal string. The UDF takes two parameters. First is the integer, here the numeric contents of the NAMES.VALUE filed. The second parameter is the width of the resulting string.

I've include a declaration in the .INIT() method code as

    EXTERNAL PROCEDURE inttohex

When I run this, I get an error:

    Variable is not found

The call stack is pointing to the line which defines the .ControlSource property.

Any suggestions?
0
Comment
Question by:IainMacb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
pcelba earned 1000 total points
ID: 40390095
You should enclose the ControlSource expression into parentheses:

    .ControlSource = "(inttohex(VAL(names.value),4))"

or

    .ControlSource = "(TRANSFORM(VAL(names.value), '@0'))"

The EXTERNAL PROCEDURE command is not necessary here.
0
 
LVL 30

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 1000 total points
ID: 40390122
As Pavel says. It's a bug of VFP9, it's defined as "by design", but it hasn't always been that way, this controlsource could have worked in earlier versions.

The problem VFP9 has, is: It could interpret inttohex (or any function name) as an array variable, parameters of the function call interpreted as indexes of an array variable. Putting an expression into outer paranthesis solves the problem.

Explanation I got some time ago: A controlsource in paranthesis is by definition an expression evaluated, leading to a readonly controlsource (oneway), while anything that could be a variable or array element could also be bound twoway (read/write). VFP then gives up stating "Variable not found".

It makes sense halfways, but in any other place in code that expression would be evaluated without the error.

Parenthesis are a general solution, if you bind to such an expression or anything else but variables or fields you want to bind to read/write. Even if you want to bind a field or variable readonly, you can do so with parenthesis.

Bye, Olaf.
0
 
LVL 1

Author Closing Comment

by:IainMacb
ID: 40390329
Wow for speed of response! :-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Visual FoxPro (short VFP) is a programming language with it’s own IDE and database, ranking somewhat between Access and VB.NET + SQL Server (Express). Product Description: http://msdn.microsoft.com/en-us/vfoxpro/default.aspx (http://msd…
Read about achieving the basic levels of HRIS security in the workplace.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question