FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour List box question
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
List box question
Posted: Mon Jan 05, 2009 12:04 AM

Does any on have some code on how to creat a list box of all dbf files within a specific directory?

Thank you

Harvey
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: List box question
Posted: Mon Jan 05, 2009 12:56 AM
Hello Harvey,

Your function :
A DBF- and NTX-file will be created : DBFFILES.dbf and FILENAME.ntx
You can select any types of files.
IF you select DBF from the main-dir, the list-dbf => DBFFILES.dbf is shown in the listbox as well.
A other solution ( if you dont want to save the result ) : show only the directory-array with XBROWSE().



// DIRDBF( <cSpec> [, <cDbf> ][, <cNtx> ][, <cDrvr> ] ) -> <nErrcode>
TEST( "*.dbf","dbffiles","filename" )
// ----------------------------------------

FUNCTION Test( spec, dbf, ntx,drvr )
LOCAL ret_val := DIRDBF( spec,dbf,ntx,drvr )
IF ret_val > 0
   IF ret_val == 1
      MsgAlert("File Spec. Not Passed", "Error")
   ENDIF		
   IF ret_val == 2
      MsgAlert("No Files Match Passed Spec.", "Error" )
   ENDIF
   IF ret_val == 3
      MsgAlert("Network Problem Creating " + upper(dbf) + ".DBF", "Error", "Error")
   ENDIF
ELSE
   USE "DBFFILES.dbf"
   XBROWSE()	
ENDIF

RETURN NIL

// ---------------------------------

FUNCTION DIRDBF( spec, dfile, ntx, driver )
LOCAL adbf, struc, orig_area, error_code := 0
FIELD name

IF spec==NIL; error_code:= 1
ELSE
   dfile := IF( dfile==NIL,"files",dfile )
   adbf  := {  {"Name","C",12,0},;
                 {"Size","N",9,0}, ;
                 {"Date","D",8,0}, ;
                 {"Time","C",8,0}, ;
                 {"Attr","C",4,0}     }

   IF EMPTY( struc:= DIRECTORY(spec) ); error_code:= 2
   ELSE
      orig_area:= SELECT()
      DBCREATE(dfile,adbf)
      USE (dfile) EXCLUSIVE NEW VIA (driver)
      IF NETERR(); error_code:= 3
      ELSE
         Aeval( struc, {|e,n| dbAppend(), ;
                              Fieldput(F_NAME,struc[n][F_NAME]),;
                              Fieldput(F_SIZE,struc[n][F_SIZE]),;
                              Fieldput(F_DATE,struc[n][F_DATE]),;
                              Fieldput(F_TIME,struc[n][F_TIME]),;
                              Fieldput(F_ATTR,struc[n][F_ATTR])   } )
         IF ntx <> NIL; INDEX ON name TO (ntx); END
         CLOSE (dfile)
         SELECT(orig_area)
      ENDIF
   ENDIF
ENDIF

RETURN ( error_code )


Regards
Uwe :-)
Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 598
Joined: Tue Apr 15, 2008 04:51 PM
Re: List box question
Posted: Mon Jan 05, 2009 04:40 AM

Uwe:

Perfect. Thanks for the quick reply.

Thank you

Harvey

Continue the discussion