Thanks a lot Rathi and Marek,
Those functions are very useful. BTW, I am already using Rathi's several functions in my code
, eg, NumWinOpened() (number of windows opened) and many SQL functions.
Is it possible to archive these UDFs with proper documentation and small usage examples? IMHO, this will be extremely helpful
I also want to re-share (
) my DbCreaChk() function which will check and create .dbf table using following logic:
1) Create if table doesn't exist.
2) Alter/Add/Remove columns from existing table.
Code: Select all
#include "dbstruct.ch"
#include "minigui.ch"
FUNCTION dbCreaChk(fname, adbf)
local aStruct, option, lChange := .f., lNew := .f., i, newrec, oldrec
fname := upper(fname)
if !file(fname+".dbf")
set exclusive on
dbcreate(fname, adbf)
set exclusive off
return .t.
endif
use (fname)
aStruct = dbstruct()
use
if len(aStruct) != len(adbf)
lChange = .t.
else
i = 1
do while i <= len(aStruct) .and. !lNew .and. !lChange
if len(aStruct[i, DBS_NAME]) != len(adbf[i, DBS_NAME]) ;
.or. upper(aStruct[i, DBS_NAME]) != upper(adbf[i, DBS_NAME]) ;
.or. upper(aStruct[i, DBS_TYPE]) != upper(adbf[i, DBS_TYPE]) ;
.or. aStruct[i, DBS_LEN] != adbf[i, DBS_LEN] ;
.or. aStruct[i, DBS_DEC] != adbf[i, DBS_DEC]
lChange = .t.
endif
i++
enddo
endif
if lChange
if msgyesno(fname+" structure has been changed. Change";
+" the structure ?")
set exclusive on
use (fname)
pack
oldrec = reccount()
use
deletefile("settemp.dbf")
if renamefile(fname+".dbf", "settemp.dbf") != 0
msginfo("Cannot change file structure!",)
QUIT
ENDIF
dbcreate(fname, adbf)
use (fname)
append from settemp
newrec = reccount()
use
if newrec != oldrec
msginfo("Problem in creating file :"+fname+;
". You can get all records in the file SETTEMP.DBF")
quit
endif
deletefile("settemp.dbf")
set exclusive off
return .t.
else
msginfo(fname+" structure mismatch")
quit
endif
endif
return .f.
function NetSelect(cTable)
if select(cTable) = 0
use &cTable shared new
endif
select (cTable)
return nil
With best regards.
Sudip