mwhitman52
Technical User
Does anyone have a procedure or the method to write to a delimited file and include the field names as the first record?
Thank you
Thank you
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
USE MyTable
nHandle = FCREATE('OUTPUT.TXT')
IF nHandle < 0
*... error routine
CLOSE ALL
RETURN
ENDIF
&&... write field name and pad with spaces, the length of field
nHowMany = AFIELDS(aFlds)
FOR nIndex = 1 TO nHowMany
=FWRITE(nHandle, PADR(aFlds[nIndex, 1], aFlds[nIndex, 3]))
NEXT
&&... write field data
nHowMany = AFIELDS(aFlds)
SCAN
STORE '' TO cTmpStr
FOR nIndex = 1 TO nHowMany
STORE '' TO cTmpData
DO CASE
CASE aFlds[nIndex, 2] = 'N'
cTmpData = PADL(ALLTRIM(STR(aFlds[nIndex, 1], ;
aFlds[nIndex, 3], aFlds[nIndex, 4])), aFlds[nIndex, 3])
CASE aFlds[nIndex, 2] = 'D'
cTmpData = ALLTRIM(DTOC(aFlds[nIndex, 1]))
CASE &&... Any other data types you use here
*...........
OTHERWISE
cTmpData = PADR(ALLTRIM(aFlds[nIndex, 1]), aFlds[nIndex, 3])
ENDCASE
cTmpStr = cTmpStr + cTmpData
=FWRITE(nHandle, cTmpData)
NEXT
ENDSCAN
=FCLOSE(nHandle)