Solved

Using UDFs in grids

Posted on 2014-10-19
3
254 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 42

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

Note: You must have administrative privileges in order to create/edit Sharing Rules. Salesforce.com (http://www.salesforce.com) (SFDC) is a cloud-based customer relationship management (CRM) system. It is a database most commonly used by sales an…
"Disruption" is the most feared word for C-level executives these days. They agonize over their industry being disturbed by another player - most likely by startups.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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