Memovelden met andere veldtypen exporteren naar een tekstbestand met Visual FoxPro

In dit artikel wordt beschreven hoe u records die memovelden in een tabel bevatten, samen met de andere veldtypen dynamisch exporteert naar een tekstbestand met komma'sscheidingstekens.

Oorspronkelijke productversie: Visual FoxPro
Origineel KB-nummer: 241424

Samenvatting

In dit artikel ziet u hoe u records die memovelden in een tabel bevatten, samen met de andere veldtypen dynamisch exporteert naar een tekstbestand met komma's.

Meer informatie

De voorbeeldcode in dit artikel volgt deze volgorde:

  1. Vraagt om een brontabel (dbf-bestand).
  2. Vraagt om een doeltekstbestand (.txt-bestand).
  3. Exporteer de inhoud van de tabel naar het tekstbestand.

De code scant en bepaalt elk veldtype en elke record in de tabel en verwerkt deze vervolgens op basis van het gegevenstype:

CLOSE ALL
CLEAR ALL

lcFieldString = ''
lcMemo = ''

USE GETFILE('dbf', 'Select DBF') && Prompts for table to be used.

lnFieldCount = AFIELDS(laGetFields) && Builds array of fields from the
&& selected table.

*!* Prompt for Output file and use Low-Level functions
*!* to create it.
lcTextFile = FCREATE(GETFILE('txt', 'Select Text'))

*!* Starts scanning the table and converts the fields
*!* values according to their types **
SCAN
    WAIT WINDOW STR(RECNO()) + ' Of ' + STR(RECCOUNT()) NOWAIT

    FOR lnCount = 1 TO lnFieldCount
        lcType = laGetFields(lnCount, 2)

        IF lcType # 'G' && Don't try to turn a general field into a string
            lcString = EVALUATE(laGetFields(lnCount, 1))
        EndIf

        DO CASE
            CASE lcType = 'M' && Process the Memo Fields
                lnMemoLines = MEMLINES(EVALUATE(laGetFields(lnCount,1)))
                FOR lnLoop = 1 TO lnMemoLines
                    IF lnLoop < lnMemoLines
                        lcMemo = lcMemo + ;
                            ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
                    lnLoop)) + ' '
                    ELSE
                        lcMemo = lcMemo + ;
                            ALLTRIM(MLINE(EVALUATE(laGetFields(lnCount, 1)), ;
                    lnLoop))
                    ENDif
                ENDfor

                lcString = lcMemo
                lcMemo = ''
            CASE lcType = 'G' && Process the General Fields
                lcString = 'Gen'
            CASE lcType = 'D' && Process the Date Fields
                lcString = DTOC(lcString)
            CASE lcType = 'T' && Process the DateTime Fields
                lcString = TTOC(lcString)
            CASE lcType = 'N' && Process the Numeric Fields
                lcString = STR(lcString, LEN(STR(lcString)), 2)
            CASE lcType = 'I' && Process the Integer Fields
                lcString = STR(lcString)
            CASE lcType = 'L' && Process the Logical Fields
                IF lcString = .T.
                    lcString = 'T'
                ELSE
                    lcString = 'F'
                ENDif
        ENDcase

        IF lnCount < lnFieldCount && Determines if the last field was
        && processed and sets the closing quote.
        lcFieldString = lcFieldString + '"' + lcString + '"' + ','
        ELSE
        lcFieldString = lcFieldString + '"' + lcString + '"'
        ENDif
    ENDfor

    FPUTS(lcTextFile, lcFieldString) && Writes string to the text file.
    lcFieldString = ''
ENDscan

FCLOSE(lcTextFile)

CLOSE All
CLEAR All
WAIT WINDOW 'Text File Creation Completed' NOWAIT