
' CreateDatabase
' Simple code to create dBase and FoxPro style databases

' This demo uses the FreeBASIC (0.24) Console compiler.


#Include Once "..\..\include\Cheetah4_FreeBasic.bi"


   
   Dim errcode   As Long
   Dim sData     As String
                            
   Cls
   
   '// CREATE A DBASE COMPATIBLE DATABASE 
   sData = "disk  = dbasetest.dbf;"    & _  
           "type  = dbase;"            & _
           "memosize = 512;"           & _     ' always 512 for dBase style databases
           "field = custid,c,8,0;"     & _     ' character
           "field = custname,c,30,0;"  & _     ' character
           "field = amountdue,n,12,2;" & _     ' numeric, 2 decimal places
           "field = lastpymt,d,8,0;"   & _     ' date
           "field = isactive,l,1,0;"   & _     ' logical y/n, t/f
           "field = notes,m,10,0;"             ' dbase memos are always size 10 

   ' Create the actual database. A second file with a .dbt extension is
   ' created to hold the memo field text. If no fields were specified 
   ' with the Memo type then the .dbt would not be created.
   errcode = xdbCreateDatabase( sData ) 
   If errcode Then GoTo ExitOut
   Print "dBase database created."


   '// CREATE A FOXPRO COMPATIBLE DATABASE 
   sData = "disk  = foxprotest.dbf;"   & _  
           "type  = foxpro;"           & _
           "memosize = 64;"            & _     
           "field = custid,c,8,0;"     & _    ' character
           "field = custname,c,30,0;"  & _    ' character
           "field = amountdue,y,8,0;"  & _    ' currency type
           "field = lastpymt,t,8,0;"   & _    ' datetime type
           "field = isactive,l,1,0;"   & _    ' logical y/n, t/f
           "field = notes,m,4,0;"             ' FoxPro memos are always size 4

   ' Create the actual database. A second file with a .fpt extension is
   ' created to hold the memo field text. If no fields were specified 
   ' with the Memo type then the .fpt would not be created.
   errcode = xdbCreateDatabase( sData ) 
   If errcode Then GoTo ExitOut
   Print "FoxPro database created."
       

ExitOut:

   ' SHUTDOWN THE SYSTEM (This will close files and free internal allocated memory)
   xdbShutdown

   Print "Demo Completed"
   
   Sleep

