Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

CLIPPER HELP!!!!!!

Status
Not open for further replies.

VNDN

Programmer
Feb 28, 2003
27
0
0
US
Hello everyone,
This is my first time writing something clipper. I am trying to append a text file with comma delimited into a DBF file but I could not figure out how to get it to work. I am just stuck. Please help me.
Thanks in advance.
 
APPEND FROM <xcFile>
[FIELDS <idField list>]
[<scope>] [WHILE <lCondition>] [FOR <lCondition>]
[SDF | DELIMITED [WITH BLANK | <xcDelimiter>]]

Use: Append from <xcFile> delimited Ian Boys
DTE Systems Ltd
 
BOZZ,
DO YOU HAVE A SAMPLE OF THE CODE THAT I CAN SEE. THANKS
 
Use myfile
append from otherfile.csv delimited with ','

Or if your database contains more fields than the csv file:

use myfile
append from otherfile.csv fields myfield1,myfield2, myfield3 delimited with ','


Rob.
 
ROB,
The file that i am appending from is a text file file.txt. Does that work the same as .csv. Thanks
 
Yes it works the same.
just fill in the filename - whatever it is - and it will do the job.

Rob.
 
I have another problem. Can anyone please take a look at this part of code. when use Seek function to seek Provno2 with same FYE but it always return as zero record. but I know for sure that we have record that match the criteria in our DBF1. Please tell me what's wrong this this code. Thanks CVL


* OPEN UPDATE DATABASE
USE Startime NEW


* OPEN PDF DATABASE
USE PDF1 NEW
INDEX ON PROVNO2 + (DTOS(FYE)) to prono

*****************************************************
* SKIP THROUGH EACH RECORD IN THE UPDATE DATABASE
* UPDATE DBF FILE
*****************************************************

DO WHILE !Startime -> (eof())
SEEK Startime ->PROVNO2 + startime -> (DTOS(FYE))
IF found()
IF !EMPTY(Startime ->AFCODE)
IF !EMPTY(PDF1 ->POA)
REPLACE POA WITH Startime ->AFCODE
ELSE
DO ERRORLINE WITH Startime ->EmployNo + &quot; &quot; + StarTime ->PROVNO2 + Startime ->(DTOC(FYE)) + &quot; POA&quot; + &quot; TARGET FIELD EMPTY &quot; +;
Startime ->POA
ENDIF
ENDIF
IF !EMPTY(startime ->DRCODE)
IF !EMPTY(PDF1 -> DRTYPE)
REPLACE drtype WITH Startime ->drcode
ELSE
DO ERRORLINE WITH Startime ->EmployNo + &quot; &quot; + StarTime ->PROVNO2 + Startime ->(DTOC(FYE)) + &quot; DRCODE&quot; + &quot; TARGET FIELD EMPTY &quot; +;
Startime ->DRCODE
ENDIF
ENDIF
IF !EMPTY(startime ->FEXITIND)
IF !EMPTY(PDF1 -> AFCOMPIND)
REPLACE afcompind WITH Startime ->fexitind
ELSE
DO ERRORLINE WITH Startime ->EmployNo + &quot; &quot; + StarTime ->PROVNO2 + Startime ->(DTOC(FYE)) + &quot; FEXITIND&quot; + &quot; TARGET FIELD EMPTY &quot; +;
Startime ->FEXITIND

ENDIF
ENDIF
IF !EMPTY(startime -> prexitind)
IF !EMPTY(PDF1 -> PREXITIND)
REPLACE prexitind WITH Startime ->prexitind
ELSE
DO ERRORLINE WITH Startime ->EmployNo + &quot; &quot; + StarTime ->PROVNO2 + Startime ->(DTOC(FYE)) + &quot; PREXITIND&quot; + &quot; TARGET FIELD EMPTY &quot; +;
Startime ->PREXITIND

ENDIF
ENDIF

RECORD++
ENDIF
SKIP ALIAS Startime
ENDDO
 

PROCEDURE __dbDelim( lNoAppend, cFile, cDelim, aFields, ;
bFor, bWhile, nNext, nRec, lRest, lMode, lNoHead )
LOCAL i, nH, aName, nPost, nLen, nCol, cIni, aRet,;
nScan, aStruct := {}, cExt, lWinMode, lHead, nMaxRow := 0,;
cTemp, cArea, cLine, xPut, aSet := {}, cFilter, bFilter
IF ISNIL(aFields)
aFields := {}
FOR i := 1 TO FCOUNT()
AADD(aFields, FIELDNAME(i))
NEXT
ENDIF
nLen := LEN(aFields)
bWhile := IIF(ISNIL(bWhile), {|| !EOF()}, bWhile)
bFor := IIF(ISNIL(bFor), {|| .T.}, bFor)
nRec := IIF(ISNIL(nRec), 1, nRec)
nNext := IIF(ISNIL(nNext), 1, nNext)
lRest := IIF(ISNIL(lRest), .T., lRest)
cDelim := IIF(ISNIL(cDelim), &quot;,&quot;, cDelim)
lMode := IIF(ISNIL(lMode), .T., lMode)
lNoHead := IIF(ISNIL(lNoHead), .F., lNoHead)
DO CASE
CASE lNoAppend
IF (nH := FCREATE(cFile, FC_NORMAL)) != -1
nCol := 0
IF !lNoHead
AEVAL(aFields, {|cName| FWRITE(nH, STRTRAN(ALLTRIM(GT_X2Char(cName)), CHR(34), CHR(39)) + IIF(++nCol != nLen, cDelim, SPACE(0)))})
FWRITE(nH, CHR(13) + CHR(10))
ENDIF
dbGoto(nRec)
DO WHILE EVAL(bWhile)
IF EVAL(bFor)
nCol := 0
AEVAL(aFields, {|cName| FWRITE(nH, ALLTRIM(GT_X2Char(FIELDGET(FIELDPOS(cName)))) + IIF(++nCol != nLen, cDelim, SPACE(0)))})
FWRITE(nH, CHR(13) + CHR(10))
ENDIF
IF !lRest
IF ++nPost >= nNext
EXIT
ENDIF
ENDIF
dbSkip()
ENDDO
FCLOSE(nH)
ENDIF

CASE !lNoAppend
cIni := SUBSTR(cFile, 0, RAT(&quot;\&quot;, cFile) - 1) + &quot;\Schema.ini&quot;
IF FILE(cIni)
aRet := ReadIni(cIni, SUBSTR(cFile, RAT(&quot;\&quot;, cFile) + 1), .T.)
IF (nScan := ASCAN(aRet, {|aName| UPPER(aName[1]) == &quot;FORMAT&quot;})) != 0
cExt := STRTRAN(aRet[nScan, 2], &quot;(&quot;, &quot;(&quot; + CHR(34))
cExt := STRTRAN(cExt, &quot;)&quot;, CHR(34) + &quot;)&quot;)
cDelim := &(cExt)
aRet := ADEL(aRet, nScan)
aRet := ASIZE(aRet, LEN(aRet) - 1)
ENDIF
IF (nScan := ASCAN(aRet, {|aName| UPPER(aName[1]) == &quot;COLNAMEHEADER&quot;})) != 0
IF UPPER(aRet[nScan, 2]) == &quot;TRUE&quot;
lHead := .T.
ELSE
lHead := .F.
ENDIF
aRet := ADEL(aRet, nScan)
aRet := ASIZE(aRet, LEN(aRet) - 1)
ENDIF
IF (nScan := ASCAN(aRet, {|aName| UPPER(aName[1]) == &quot;CHARACTERSET&quot;})) != 0
lWinMode := IIF(aRet[nScan, 2] == &quot;ANSI&quot;, .T., .F.)
aRet := ADEL(aRet, nScan)
aRet := ASIZE(aRet, LEN(aRet) - 1)
ENDIF
IF (nScan := ASCAN(aRet, {|aName| UPPER(aName[1]) == &quot;MAXSCANROWS&quot;})) != 0
nMaxRow := VAL(aRet[nScan, 2])
aRet := ADEL(aRet, nScan)
aRet := ASIZE(aRet, LEN(aRet) - 1)
ENDIF
AEVAL(aRet, {|aName| IIF(AT(&quot;COL&quot;, UPPER(aName[1])) != 0, AADD(aStruct, GetShema(aName, aSet, lWinMode)), NIL)})
cArea := ALIAS()
// cTemp := GetNTemp(cPathTemp + '\~Txt', 4)
cTemp := GetNTemp(cPathTemp + '\')
// __HelpArr(aStruct, {&quot;Èìå&quot;,&quot;Ìîäåë&quot;,&quot;Äúë&quot;,&quot;Òî÷&quot;}, 1)
dbCreate(cTemp, aStruct, &quot;DBFCDX&quot;)
NETUSE(.T.,, cTemp, 'TXTTEMP', .F.)
aSet := TXTTEMP -> (LUPDATESETTINGS(1, ID_EMPTY,, aSet))
ft_fUse(cFile, FO_READ)
IF lHead
ft_fGoto(2)
ENDIF
DO WHILE !ft_fEof()
TXTTEMP -> (dbAppend())
cLine := ft_fReadLn()
// OnLineHelp(cLine)
// Inkey(0)
FOR i := 1 TO TXTTEMP -> (FCOUNT())
xPut := TOKEN(cLine, cDelim, i, LEN(cDelim))
IF aStruct[i, 2] == &quot;N&quot;
xPut := STRTRAN(xPut, &quot;,&quot;, SPACE(0))
ENDIF
xPut := GT_Char2X(xPut, aStruct[i, 2])
IF aStruct[i, 2] == &quot;C&quot; .AND. lWinMode
xPut := ConvWinOem(xPut)
ENDIF
TXTTEMP -> (FIELDPUT(i, xPut))
NEXT
aSet := TXTTEMP -> (LUPDATESETTINGS(1, ID_PUT,, aSet))
ft_fSkip()
ENDDO
ft_fUse()
TXTTEMP -> (LUPDATESETTINGS(1, ID_SAVE,, aSet))
TXTTEMP -> (dbCloseArea())
IF !EMPTY(cArea)
SELECT (cArea)
ENDIF
cFile := cTemp
ELSE
IF !EMPTY(cArea := ALIAS())
ft_fUse(cFile, FO_READ)
DO WHILE !ft_fEof()
(cArea) -> (dbAppend())
cLine := ft_fReadLn()
FOR i := 1 TO (cArea) -> (FCOUNT())
(cArea) -> (FIELDPUT(i, GT_Char2X(TOKEN(cLine, cDelim, i, LEN(cDelim)), dbFieldInfo(DBS_TYPE))))
NEXT
ft_fSkip()
ENDDO
ft_fUse()
SELECT (cArea)
ENDIF
ENDIF

ENDCASE
RETURN

STATIC FUNCTION GetShema(aVar, aS, lW)
LOCAL aRet := {}, cName, cAName, cMode, nLen, nDec
cName := aVar[1]
cAName := IIF(LEFT(aVar[2], 1) == CHR(34), STRTRAN(TOKEN(aVar[2], CHR(34), 2, 1), SPACE(1), &quot;;&quot;), TOKEN(aVar[2], SPACE(1), 1, 1))
cAName := IIF(lW, ConvWinOem(cAName), cAName)
cMode := GetSMode(ALLTRIM(IIF(LEFT(aVar[2], 1) == CHR(34), TOKEN(aVar[2], CHR(34), 3, 1), SUBSTR(aVar[2], AT(SPACE(1), aVar[2])))))
nDec := GetSDec(ALLTRIM(IIF(LEFT(aVar[2], 1) == CHR(34), TOKEN(aVar[2], CHR(34), 3, 1), SUBSTR(aVar[2], AT(SPACE(1), aVar[2])))), @nLen)
aRet := {cName, cMode, nLen, nDec}
AADD(aS, {cName, cAName, cMode, nLen,,})
RETURN aRet

STATIC FUNCTION GetSMode(cMode)
cMode := TOKEN(cMode, SPACE(1), 1, 1)
DO CASE
CASE UPPER(cMode) == &quot;CHAR&quot; .OR. ;
UPPER(cMode) == &quot;LONGCHAR&quot; .OR. ;
UPPER(cMode) == &quot;BIT&quot; .OR. ;
UPPER(cMode) == &quot;BYTE&quot;

cMode := &quot;C&quot;

CASE UPPER(cMode) == &quot;INTEGER&quot; .OR. ;
UPPER(cMode) == &quot;FLOAT&quot; .OR. ;
UPPER(cMode) == &quot;SHORT&quot; .OR. ;
UPPER(cMode) == &quot;SINGLE&quot; .OR.;
UPPER(cMode) == &quot;CURRENCY&quot;

cMode := &quot;N&quot;

CASE UPPER(cMode) == &quot;DATE&quot;
cMode := &quot;D&quot;

ENDCASE
RETURN cMode

STATIC FUNCTION GetSDec(cMode, nWidth)
LOCAL nDec := 0
nWidth := VAL(TOKEN(cMode, SPACE(1), 3, 1))
nWidth := IIF(nWidth == 255, 254, nWidth)
cMode := TOKEN(cMode, SPACE(1), 1, 1)
DO CASE
CASE UPPER(cMode) == &quot;CHAR&quot; .OR. ;
UPPER(cMode) == &quot;LONGCHAR&quot;

CASE UPPER(cMode) == &quot;BIT&quot;
nWidth := 1

CASE UPPER(cMode) == &quot;BYTE&quot;
nWidth := 2

CASE UPPER(cMode) == &quot;INTEGER&quot; .OR. ;
UPPER(cMode) == &quot;FLOAT&quot; .OR. ;
UPPER(cMode) == &quot;SHORT&quot; .OR. ;
UPPER(cMode) == &quot;SINGLE&quot; .OR.;
UPPER(cMode) == &quot;CURRENCY&quot;

nWidth := 15
nDec := 3

CASE UPPER(cMode) == &quot;DATE&quot;
nWidth := 8

ENDCASE
RETURN nDec

FUNCTION Delimited(cDel)
RETURN cDel
 
Thanks you so much for all your help, everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top