******************************************************************** * Description.......: ChangeDBCName - changes DBC Name using low-level functions * Calling Samples...: * Parameter List....: tcTableFullName, tcOldDBCName, tcNewDBCName * Created by........: Sergey Berezniker * Modified by.......: Nadya Nosonovsky 05/22/2002 09:35:06 AM ******************************************************************** lparameters tcTableFullName, tcOldDbcName, tcNewDBCName if vartype(m.tcTableFullName)<>"C" tcTableFullName = getfile('DBF','Select','&Choose',0,'Select table to check database') if empty(m.tcTableFullName) && User pressed cancel return '' endif endif if vartype(m.tcOldDBCName)<>"C" tcOldDBCName = rbInputBox('Enter Old DBC with extension','Old DBC Name') if empty(m.tcOldDBCName) return .f. endif endif if vartype(m.tcNewDBCName)<>"C" tcNewDBCName = rbInputBox('Enter New DBC with extension','New DBC Name') if empty(m.tcNewDBCName) return .f. endif endif local lcDbcFullName, lcB1, lcB2, lnOffset, lcBuffer, lnFh1 lnFh1 = fopen(m.tcTableFullName,12) && To read-write if m.lnFh1 > 0 * Make sure that's VFP table lcBuffer = fread(m.lnFh1,1) if asc(m.lcBuffer) <> 0x30 * not VFP table lcDbcName = "***NOT VFP TABLE***" = messagebox(m.lcDbcName,48,'Error') return .f. else * table in dbc lcDbcName = left(m.lcBuffer, at( chr(0), m.lcBuffer) - 1) endif * Position of the first data record - 2 bytes = fseek(m.lnFh1, 8, 0) lcB1 = fread(m.lnFh1,1) lcB2 = fread(m.lnFh1,1) * Offset to the beginning of the DBC name lnOffset = asc(m.lcB2) * 256 + asc(m.lcB1) - 263 = fseek(m.lnFh1, m.lnOffset, 0) * The DBC name or 0x00's if it's free table lcBuffer = fread(m.lnFh1, 263) if asc(m.lcBuffer) = 0 * free table lcDbcName = "***FREE TABLE***" = messagebox(m.lcDbcName,48,'Error') return .f. else * table in dbc if not lower(m.tcOldDBCName) $ m.lcBuffer =messagebox ('The database '+ m.tcOldDBCName + ' is not the Database name for this table',48,'Different database') return .f. endif lcBuffer = strtran(m.lcBuffer,m.tcOldDBCName,m.tcNewDBCName) = fseek(m.lnFh1, m.lnOffset, 0) if fwrite(m.lnFh1, m.lcBuffer)=0 = messagebox('New DBC name could not be written to the file!',48,'No change') return .f. endif lcDbcName = left(m.lcBuffer, at( chr(0), m.lcBuffer) - 1) endif = fclose(m.lnFh1) else =messagebox('File '+m.tcTableFullName+' could not be opened',48,'Problem') return .f. endif return .t.&&m.lcDbcNameP.S. once again, it's good, that I published it, because I see, I need to modify comments, prompts, etc. a little bit.