Solved

Using UDFs in grids

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Oracle Apps Profiles option: A user profile is a set of shifting options that alter the way one runs an application. A value is set for each option under the user's profile when the Oracle application user logs on to any responsibility or changes…
"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.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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