What is the best way to fill an array from a dbf-file (a kind of recordset).
Thanks in advance
Otto
# include "Common.ch"
# DEFINE MAAKBLCK(cvar) &("{||"+cvar+"}")
# DEFINE MAAKINDBLCK(var,indexorde) var := &("{||"+INDEXKEY(indexorde)+"}")
*********************************************************************************************************
PROC ReadDbf(Arr,ArrColBlock,cFilter, uFrom , uTo , cOrder )
***************************************************************
// ArrColBlock may be nil (all fields are selected) , array from fieldnames or Codeblocks
LOCAL bFilt , IndBlck , HlpArr[0] , el
LOCAL j
LOCAL GehOrd
LOCAL Hlp
LOCAL aStruct := DbStruct() , aFields[0]
Aeval(aStruct , {|x|AADD(aFields,x[1])})
CursorWait()
Arr := {}
IF IsCharacter(cFilter)
bFilt := MAAKBLCK(cFilter)
ELSEIF IsBlock(cFilter)
bFilt := cFilter
END
IF IsNil(ArrColBlock) .OR. ! IsArray(ArrColBlock)
ArrColBlock := {}
FOR j := 1 TO FCOUNT()
AADD(ArrColBlock,FIELDBLOCK(FIELD(j)))
NEXT
END
FOR EACH el IN ArrColBlock
IF IsCharacter(el) .AND. ASCAN(aFields, UPPER(el)) > 0
el := FIELDBLOCK(el)
END
IF ! IsBlock(el)
Msginfo("Wrong column " + LTRIM(STR(Hb_EnumIndex()))
RETURN
END
NEXT
IF (IsCharacter(cOrder) .OR. IsNumber(cOrder)) .AND. OrdSetFocus() <> cOrder
GehOrd := OrdSetFocus(cOrder)
END
IF IndexOrd() > 0
MAAKINDBLCK(IndBlck,indexord())
IF ! IsNil(uFrom)
IF IsBlock(uFrom)
uFrom := EVAL(uFrom)
END
DBSEEK(uFrom,.T.)
ELSE
GO TOP
END
IF ! IsNil(uTo)
IF IsBlock(uTo)
uTo := EVAL(uTo)
END
END
ELSE
IF ! IsNil(uFrom) .AND. IsNumber(uFrom)
IndBlck := {||RECNO()}
IF !( !IsNil(uTo) .AND. IsNumber(uTo) )
uTo := LASTREC()
END
DBGOTO(uFrom)
ELSE
GO TOP
END
END
DO WHIL ! EOF() .AND. IIF(! IsNil(uTo) .AND. IsBlock(IndBlck), EVAL(indBlck) <= uTo , .T. )
IF ! IsBlock(bFilt) .OR. EVAL(bFilt)
ASIZE(hlparr,0)
FOR EACH el IN ArrColBlock
hlp := EVAL(el)
AADD(hlparr , Hlp) //EVAL(el:bData))
NEXT
AADD(arr,ACLONE(hlparr))
END
SKIP
ENDD
IF ! IsNil(GehOrd)
OrdSetFocus(GehOrd)
END
CursorArrow()
RETURN
FUNCTION MAIN()
LOCAL aArray := {}
LOCAL i
USE TEST
WHILE !EOF()
AADD( aArray, {} )
FOR i = 1 TO FCOUNT()
AADD( ATAIL( aArray ), FIELDGET( i ) )
NEXT
SKIP
ENDDO
CLOSE
// here you have the filled array
RETURN NIL
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: No registered users and 88 guests