Solved

Using UDFs in grids

Posted on 2014-10-19
3
226 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
3 Comments
 
LVL 41

Accepted Solution

by:
pcelba earned 250 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 29

Assisted Solution

by:Olaf Doschke
Olaf Doschke earned 250 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In our personal lives, we have well-designed consumer apps to delight us and make even the most complex transactions simple. Many enterprise applications, however, are a bit behind the times. For an enterprise app to be successful in today's tech wo…
Messaging apps are amazing tools with the power to do a lot of good, but the truth is the process of collaborating with coworkers requires relationships established through meaningful communication - the kind of communication that only happens face-…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now