Suggestion and request for DBF plugin

May 29, 2008
529
3
Groton, CT
#1
Joe,

(I couldn't find your email address either here or on your website. If I had been able to find it, I would have written you privately.)

It would be useful to have a new function in the DBF plugin, for returning the record number in which a file byte offset resides.

Example:

I want to find the record containing the word FOOBAR.
Code:
SET XX=%@EXECSTR[FFIND /K /M /T"FOOBAR" /X TEST.DBF]
SET XX=%@EVAL[%@WORD["()h",1,%XX]]
Now, in order to read the record containing the target word, I need the record number.
The computation is %@eval[(%xx% - (start address of record 1)) \ %@recsize[test.dbf]) + 1] .

How about %@recnum[dbffile,fileoffset] ? Let it return -1 if the address given precedes the start of record 1.

This would then allow this to follow the above code:
Code:
SET RN=%@RECNUM[TEST.DBF,%XX]
SET TARGET_RECORD=%@RECORD[TEST.DBF,%RN]
Alternatively, maybe you could supply the file byte offset of the start of record 1 and I could do the rest of the arithmetic myself.
 
#2
Joe,

Alternatively, maybe you could supply the file byte offset of the start of record 1 and I could do the rest of the arithmetic myself.
Hello Dave,
Thanks for the suggestion. I will work on it, and hope to have your solution posted tomorrow in an updated plugin.

Take a look at Read dBase database (.DBF) to see how to access a .DBF using only a TCC script, if you want to find the file byte offset of record 1 on your own.

Since I discovered XBScript, I have not used my plugin, as XBScript allows me to get all the info I need from a .DBF

It would be great if TCC would allow the use of COM objects, allowing the use of commands and functions from other applications/ActiveX servers. Hey, there's an idea for a new plugin!

Until then, CSCRIPT/SCRIPT and XBScript is the solution for my access to .DBF files from TCC.

Joe
 
May 29, 2008
529
3
Groton, CT
#3
Hello Dave,
Thanks for the suggestion. I will work on it, and hope to have your solution posted tomorrow in an updated plugin.

Take a look at Read dBase database (.DBF) to see how to access a .DBF using only a TCC script, if you want to find the file byte offset of record 1 on your own.

Since I discovered XBScript, I have not used my plugin, as XBScript allows me to get all the info I need from a .DBF

It would be great if TCC would allow the use of COM objects, allowing the use of commands and functions from other applications/ActiveX servers. Hey, there's an idea for a new plugin!

Until then, CSCRIPT/SCRIPT and XBScript is the solution for my access to .DBF files from TCC.

Joe
Thanks, Joe. I guess that even without reading the value out of offset 0x0A, I could compute it from 32 * %@fieldcount[xx.dbf] + 34.
 
#5
Code:
::+--------------------------------------------------------------------+
::| TEST_RECNUM.BTM                                                    |
::| Test the @RECNUM function of the DBF.DLL plugin                    |
::|                                                                    |
::| Joe Caverly                                                        |
::| February 13, 2012                                                  |
::|                                                                    |
::| USAGE:  TEST_RECNUM text2searchfor myfile.dbf                      |
::+--------------------------------------------------------------------+
@setlocal
@echo off
if not plugin dbf plugin /l dbf
iff %# eq 2 then
  set searchTerm=%1
  set thedbf=%2
  iff not exist %thedbf then
    echo The file %thedbf does not exist
    goto eoj
  endiff
else
  echo USAGE: TEST_RECNUM text2searchfor myfile.dbf
  goto eoj
endiff
echo Searching for %searchTerm
::
:: Search the .DBF file for the searchTerm, returning;
::   /k (No Headers)
::   /m (No Footers)
::   /x (Return Offset In Both Decimal And Hexadecimal)
::   /t (Search For Text)
::
set xx=%@execstr[ffind /kmxt"%searchTerm" %thedbf]
::
:: if the search was successful, then environment variable xx will be
::   defined.
::
iff defined xx then
  ::
  :: %searchTerm was found
  :: Extract the decimal offset
  ::
  set xx=%@EVAL[%@WORD[1,%XX]]
  ::
  :: Restriction:
  ::   Let's say that you have a field in your .DBF file called
  ::   THESTRING.
  ::   If you do a search in your .DBF for the searchTerm string,
  ::     @RecNum will return an Invalid Offset error, since the
  ::     searchTerm will first be found in the header of your .DBF
  ::
  ::   Use the new @FirstRecOffset function to find the offset of where
  ::     the first record begins, allowing you to skip over the header
  ::     of your .DBF file.
  ::
  ::
  :: If we give the @recnum function the decimal offset, it will tell us
  ::  the record number
  ::
  set rn=%@recnum[%thedbf,%xx]
  ::
  :: If the offset is less than 1, or less than the offset of the First Record in the .dbf,
  ::   or greater than the length of the .dbf, then -1 is returned.
  ::
  iff %rn eq -1 then
    echo %xx is an Invalid Offset
    goto eoj
  endiff
  set target_record=%@record[%thedbf,%rn]
  ::
  :: Logically, the record number should be valid, but if it is not, then -1 is returned.
  ::
  iff %target_record eq -1 then
    echo Record Number Not In Range 1:%reccount[%thedbf]
    goto eoj
  else
    echo RecNum is:` `%rn
    echo Target Record is:` `%target_record
  endiff
  plugin /u dbf
else
  echo %searchTerm not found in %thedbf
endiff
:eoj
endlocal