List box question

List box question

Postby hag » 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
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California

Re: List box question

Postby ukoenig » 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().

Image

Code: Select all  Expand view

// 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 :lol:
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.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: List box question

Postby hag » Mon Jan 05, 2009 4:40 am

Uwe:

Perfect. Thanks for the quick reply.
Thank you
Harvey
hag
 
Posts: 598
Joined: Tue Apr 15, 2008 4:51 pm
Location: LOs Angeles, California


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 99 guests