Announcement

Collapse
No announcement yet.

FTP / Btrieve Questions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Claudio DalZovo
    replied
    Using Btrieve (from version 6.15 to psql9) is rather simple.
    All you need is the interface dll (wbtrv32.dll) and of course one version of Btrieve installed.

    Here an example of how read a Btrieve file and write data records on a random access file in the same way the Btrieve utilities BUTIL.EXE do.

    Sample is simplified; things are a bit more complex to manage more files at once.
    If you wish I can post examples of how to write to a file, delete records and so on.
    Using Btrieve however requires some info and concepts quite long to explain, you can find it on Btrieve manuals.
    Tsunami, referenced in previous posts, is very similar and perfect for small applications.
    However if you already have existing Btrieve file to read ... you need Btrieve, not Tsunami

    The code is for a batch program in PBCC, but difference are only in writing results and errors; Btrieve calls are the same as in PBWin.

    Code:
          declare function btrcall lib "wbtrv32.dll" alias "BTRCALL" (byval op as integer,pb as any,db as any,byref dl as integer,kb as any,byval kl as integer,byval kn as integer) as integer
    
    Function PBMain() as long
          local posblkz as string * 128
          local chiavez as string * 256
          local btrbufz as string * 2048
    
          cmd$=ucase$(command$)
          cmd$=trim$(command$)
    
          filebtr$=""
          fileseq$=""
          i%=instr(cmd$," ")
          if i% then
             filebtr$=trim$(left$(cmd$,i%-1))
             fileseq$=trim$(mid$(cmd$,i%+1))
          end if
          if filebtr$="" or fileseq$="" then
             stdout "Error, Btrieve filename or output filename missing"
             exit function
          end if
    
          stdout filebtr$+" -> "+fileseq$
    
          op%=0 ' open
          buffer$=""
          buflen%=0
          chiave$=filebtr$+chr$(0)
          chiave%=-1
          gosub Btr
    
          op%=15 ' stat
          buffer$=space$(1000)
          buflen%=1000
          chiave$=space$(255)
          chiave%=0
          gosub Btr
    
          lun%=cvi(mid$(buffer$,1,2))
          lun$=trim$(str$(lun%))
          lunlun%=len(lun$)+1
          open fileseq$ for output as #1
          close #1
          open fileseq$ for random as #1 len=lun%+lunlun%+2
          rec1$=space$(lun%+lunlun%+2)
          mid$(rec1$,1,lunlun%)=lun$+","
          mid$(rec1$,lun%+lunlun%+1,2)=chr$(13)+chr$(10)
          rec1!=0!
          mille%=0
    
          op%=9 ' get >=
          buffer$=space$(lun%)
          buflen%=lun%
          chiave$=string$(255,0)
          chiave%=0
          gosub Btr
          do while status%=0
             mid$(rec1$,lunlun%+1,lun%)=buffer$
             rec1!=rec1!+1!
             put #1, rec1!, abs rec1$
             mille%=mille%+1
             if mille%=1000 then
                mille%=0
                if istrue consout then
                   stdout "*"; ' simple progress display
                end if
             end if
             op%=6 ' get next
             buffer$=space$(lun%)
             buflen%=lun%
             chiave%=0
             gosub Btr
          loop
    
          op%=1 ' close
          buffer$=""
          buflen%=0
          chiave$=filebtr$+chr$(0)
          chiave%=0
          gosub Btr
    
          stdout
          stdout "Records saved"+str$(rec1!)
    
          exit function
    
    
          ' Btrieve calls (should be #included in source or modified to a sub/function)
          ' op%                 ' operation
          ' buffer$             ' data record or parameters for file create
          ' buflen%             ' data reford length
          ' chiave$             ' key for get or filename for open/close,
          '                       must be long enough!
          ' chiave%             ' key number or open mode for open
          ' posblk$             ' file info, set from open/close,
          '                       must be passed on subsequent calls
          ' status%             ' Status
    
       Btr:
          select case op%
             case 0 ' open
                posblk$=space$(128)
                gosub ChiamataBtrieve
             case 1 ' close
                gosub ChiamataBtrieve
                posblk$=""
             case 14 ' create
                posblk$=space$(128)
                gosub ChiamataBtrieve
                posblk$=""
             case else
                gosub ChiamataBtrieve
          end select
          return
    
       ChiamataBtrieve:
          status%=0
          posblkz=posblk$
          btrbufz=buffer$
          chiavez=chiave$
          keylen%=len(chiave$)
          status%=btrcall(op%,posblkz,btrbufz,buflen%,chiavez,keylen%,chiave%)
          posblk$=posblkz
          buffer$=btrbufz
          chiave$=left$(chiavez,keylen%)
          posblkz=""
          btrbufz=""
          chiavez=""
          if status%<>0 and status%<>4 and status%<>9 then ' only status ok, not found and eof are returned, other errors are trapped
             gosub ErroreBtrieve
          end if
          return
    
       ErroreBtrieve:
          stdout "Btrieve Error (Op"+str$(op%)+", Status"+str$(status%)+")"
          while inkey$=""
          wend
          if status%<>20 then
             op%=28 ' reset all resource
             buffer$=""
             buflen%=0
             chiave$=""
             chiave%=0
             posblk$=space$(128)
             gosub ChiamataBtrieve
          end if
          cls
          close
          exit function
    
    End Function
    Last edited by Claudio DalZovo; 26 Oct 2007, 07:49 PM.

    Leave a comment:


  • Mike Doty
    replied
    Jim,
    If you like Btrieve then Tsunami by Timm Motl will interest you.
    Don Dickinson wrote TTDS to handle client/server for Tsunami.
    Don also has some Btrieve wrappers (not sure where they are.)

    http://www.trm-ug.com/

    Leave a comment:


  • Roy Cline
    replied
    I found the Btrieve consatants some where, if you don't
    find them I can email you one I have, if you want.

    Leave a comment:


  • Steve Rossell
    replied
    Originally posted by Mike Trader View Post
    Hello Jim,

    Look for the PB code archive. Its called Poffs.
    Download and install
    Search for FTP in the subject
    Actually I think you would be better off searching the forums as you will find more recent content and it has more search features. See http://www.powerbasic.com/support/pb...196#post263196 for a list of the advanced boolean search options available for use in the forums.

    Leave a comment:


  • Mark Strickland
    replied
    Some ideas

    If you search these forums for FTP and Don Dickson you will find some public domain FTP code. I personally use SocketTools from Catalyst.com. It is not free but has lots of options beyond just FTP.

    You can take several approaches to Un-ZIPPING. One would be the "poor man's approach" by just SHELLing to the appropriate command line un-zipper program (7Zip comes to mind). You can also find here lots of posts about ZLIB (a free compression library).

    If you search this forum for Betrieve you should find some code snippets and you may be able to "roll your own" in terms of reading a Betrieve file. Plan B could be an ODBC driver (but that would require some SQL tools from somebody like Perfect Sync). I am sure somebody here can find a Plan C if these don't work for you.

    If you are new to PowerBASIC you might take an "iterative" design approach. Start simple (like SHELL to the un-zipper program), get that working, then build your own function to replace the SHELL command.

    This way you can get familiar then raise the level of complexity.

    If you are looking for a GUI frontend to design graphical user interfaces PowerBASIC has PowerFORMS that will generate native DDT code. You can use EZgui, PowerDev, or my favorite FireFly. Check out the Built With PowerBASIC link on the main PowerBASIC.com website for lots of options.

    Don't forget to visit here also.
    http://www.jose.it-berater.org/smfforum/index.php

    Don't be afraid to post your questions here. These forums are filled with the best and most helpful people on the planet.

    Leave a comment:


  • Mike Trader
    replied
    Hello Jim,

    Look for the PB code archive. Its called Poffs.
    Download and install
    Search for FTP in the subject

    Don Dickenson has some code for FTP
    http://www.powerbasic.com/support/fo...ML/012352.html

    For unzipping you will need to implement zlib.dll wrappers

    What created the Btrieve files?
    What format are they?

    Leave a comment:


  • Jim Stephenson
    started a topic FTP / Btrieve Questions

    FTP / Btrieve Questions

    I am extremely new to PowerBasic and am looking for some advice. I have two projects I would like to do using PowerBasic: One is a simple FTP download of some zip files from a server and then unzipping the files into their appropriate folders; The second is accessing some btrieve files for displaying a table/grid. I am just looking for some general advice on how to get started and where to look for some examples.

    Thanks,
    Jim Stephenson
Working...
X