2
votes

I am VERY new to FoxPro so please pardon what is most likely a very silly question. I am trying to wrap my brain around several FoxPro 9 programs that were written by a non-programmer and, having never looked at FoxPro code before in my life, am finding it quite a chore to understand some of it's idiosyncrasies.

I have a pretty simple SQL statement that is returning information from the Project file(being used as a table). I have three simple functions that handle giving me some useful information about the objects (files) that are included in the project.

Here is the entire main program that gets run. It's nothing but a single SQL statement that uses three simple functions:

SELECT ShortName(Name) AS SName, LongName(Name) AS LName, Type, GetType(Type) AS TypeName ;
FROM <my project file here> ;
ORDER BY Type, SName

The SQL statement runs fine and my three functions get called and all three return the data I expect with the exception of the GetType function. The ShortName function returns just the file name, the LongName function returns the entire path and file name and the GetType function is supposed to return a more human readable string that tells me what the file type is. Such as "Table", "Program", etc . . .

HERE IS THE PROBLEM:

The GetType function is being run and the return value is being set but the value being returned is being truncated to 6 characters.

enter image description here

I have verified that the return value of the function is the full string of text that I expect just before the function exits. However; when the data is displayed in the viewer the value is truncated.

Why is this data being truncated? The two other functions work nearly the same way (at least from my completely "un-knowledgeable" view point) and they are not being truncated.

Here is the code from the GetType function

PARAMETERS pType

retVal = ""

DO CASE
    CASE LEFT(ALLTRIM(pType),1) = 'B'
        retVal  = "Lable"
    CASE LEFT(ALLTRIM(pType),1) = 'D'
        retVal  = "Table"
    CASE LEFT(ALLTRIM(pType),1) = 'd'
        retVal  = "XBase Table"
    CASE LEFT(ALLTRIM(pType),1) = 'F'
        retVal  = "Format"
    CASE LEFT(ALLTRIM(pType),1) = 'H'
        retVal  = "Header"
    CASE LEFT(ALLTRIM(pType),1) = 'I'
        retVal  = "Index"
    CASE LEFT(ALLTRIM(pType),1) = 'L'
        retVal  = "Library"
    CASE LEFT(ALLTRIM(pType),1) = 'M'
        retVal  = "Menu"
    CASE LEFT(ALLTRIM(pType),1) = 'P'
        retVal  = "Program"
    CASE LEFT(ALLTRIM(pType),1) = 'Q'
        retVal  = "Query"
    CASE LEFT(ALLTRIM(pType),1) = 'R'
        retVal  = "Report Form"
    CASE LEFT(ALLTRIM(pType),1) = 's'
        retVal  = "Screen Table"
    CASE LEFT(ALLTRIM(pType),1) = 'S'
        retVal  = "Screen Program"
    CASE LEFT(ALLTRIM(pType),1) = 'T'
        retVal  = "Configuration File"
    CASE LEFT(ALLTRIM(pType),1) = 'x'
        retVal  = "File"
    CASE LEFT(ALLTRIM(pType),1) = 'X'
        retVal  = "File"
    CASE LEFT(ALLTRIM(pType),1) = 'Z'
        retVal  = "Application"
ENDCASE 

RETURN retVal
3

3 Answers

5
votes

Actually, shorter, have your Function GetType(), always return the "PADR( retVal, 15 )" (or whatever length).

Reason being. When VFP runs a query, it actually runs it TWICE. First time checks to make sure its valid, and looks at function calls to ensure a given type for the result. If your query on the first record returns a shorter string length value, so too is the final cursor that column width.

By enforcing a full - constant length from your function you will guarantee it won't be truncated, nor missed in any other SQL call elsewhere.

3
votes

Replace your SQL SELECT with:

SELECT ShortName(Name) AS SName, LongName(Name) AS LName, Type, PADR(GetType(Type), 10) AS TypeName ;
FROM <my project file here> ;
ORDER BY Type, SName

This will pad right the resulting text with the appropriate number so spaces until the result is 10 characters. Adjust the value as you need.

This happens becuase SQL SELECT determines column widths based on the first record returned.

-1
votes

You are getting a truncated return because the first item found in the SELECT is what determines the length. Pad you answer with '00000000000000' or something to correct this. Have you ever heard of ProMatrix? Super powerful VFP overlay builder. I have used it for several years and really helped me with the learning curve. HTH