Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Display description in a grid column rather than code
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire d'écran & Écrans
Divers
Thread ID:
00490488
Message ID:
00490835
Vues:
9
>>>Hi Barbara,
>>>
>>>The problem here, that I don't have code+description as a separate table. I created an include file, where I set variables, like APNEDT "E", etc. I was thinking, is it possible to set controlsource like iif(APNEDT,APNEDTDESC,...). Since there are ~5 different values, it would not be convenient to use iif, it's better to use some function here. My question is: could it be done?
>>
>>You could set a function as the controlsource of a textbox, which would have that one-char field as a parameter, and return the string.
>
>Could it be a form method? E.g. in properties ControlSource put something like:
>thisform.GetDescription(APN)?

I don't use a form method for this stuff as I tend to use it EVERYWHERE. Since all of our coded values are based on lookup, I use a common routine everywhere (reports, forms etc.)

Here is the code for it, I call it gencodelookup. Just so you understand, most of our lookup tables use what I have heard called "table overloading" where we have a field called subfile that breaks the table up into many virtual lookup tables. Our lookup program is designed to work with this lookup table structure. Also we use a standardized lookup table structure which consists of a minimum 4 fields. Code (the stored coded value), Text (the decoded text describing the code) subfile (this breaks the table into virtual tables) and pickorder (this is used by our pulldowns to allow for custom sorting). BTW, our development standards say that all databases and tables are to be on the VFP path, and unique within the path, so that we can open any table or database without having to know the path (we set the path at the beginning of the program).

************************************************************
* Function....: GenCodeLookup
* Called by...:
*
* Abstract....:
*
* Returns.....: lcCodeDescription. This is either the lookup
* value from the requested file, or is the code
* that was sent to the function
*
* Parameters..: pcFile = The Lookup database to search
* pcFindValue = The value to search for
* pcSubFile = This allows me to find the subfile in Picklist
*
* Notes.......: This routine was written to allow me to use
* lookup databases in reports without having
* to either set up relations into all the files
* being used, or having to put the text of all
* the codes into memory variables first.
************************************************************
PARAMETERS pcfile, pcfindvalue, pcsubfile
PRIVATE lcalias, lccodedescription, lparms
lparms = PARAMETERS()
*--- Store the current area
lcalias = ALIAS()
*-- Select the requested database
IF USED(pcfile)
SELECT (pcfile)
ELSE
USE (pcfile) IN 0
SELECT (pcfile)
ENDIF
*-- Search for the requested information
IF lparms = 3
LOCATE FOR TRIM(CODE) == TRIM(pcfindvalue) .AND. TRIM(subfile) == TRIM(pcsubfile)
ELSE
LOCATE FOR TRIM(CODE) == TRIM(pcfindvalue)
ENDIF
IF FOUND()
*- If you got it, store the return value
lccodedescription = TEXT
IF RIGHT(TRIM(lccodedescription),1) = ":"
lccodedescription = LEFT(lccodedescription,LEN(TRIM(lccodedescription))-1)
ENDIF
ELSE
*- if not found, store the code as a character, unless its 0
*- in which case you return "Unknown/Don't Know"
lccodedescription = pcfindvalue
*- if not found, store the code as a character, unless its 0
*- in which case you return "Unknown/Don't Know"
DO CASE
CASE TYPE("pcFindValue") = "C"
lccodedescription = pcfindvalue
CASE TYPE("pcFindValue") = "N"
IF pcfindvalue = 0
lccodedescription = "Unknown/Don't Know"
ELSE
lccodedescription = ALLTRIM(STR(pcfindvalue))
ENDIF
OTHERWISE
lccodedescription = "**Unknown Data Type**"
ENDCASE
ENDIF
*-- Select the original work area
IF !EMPTY(lcalias)
SELECT (lcalias)
ENDIF
*-- Return with the requested information
RETURN lccodedescription
*EOF GenCodeLookup
Cy Welch
Senior Programmer/Analyst
MetSYS Inc
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform