Accessing the API directly is the easy part -- all you do is make the function
call. Understanding how to set up the parameters is the hard part, and this is
what the Programmers Reference goes into. You should be able to compile the
sample code in the SDK and use that as a jumping-off point, though.
Goldstar Software Inc.
Building on Btrieve(R) for the Future(SM)
Bill Bach
Bill...@compuserve.com
http://www.goldstarsoftware.com
*** Pervasive.SQL Service & Support Courses ***
Chicago: February 5-8, 2001 - See our web site for details!
"Bill Bach" <bb...@cncdsl.com> wrote in message
news:3C261813...@cncdsl.com...
have fun,
Darren L. Oldag
Pervasive Software
-------------
Attribute VB_Name = "BtrSam32"
Rem **********************************************************************
Rem
Rem Copyright 1994-1997 Pervasive Software Inc. All Rights Reserved
Rem
Rem *********************************************************************
Rem BTSAMP32.VBP
Rem BTRFRM32.FRM
Rem BTRSAM32.BAS
Rem This is an example program that demonstrates the Visual Basic
Rem interface to Btrieve. A Visual Basic program must use the
Rem Windows-specific interface WBTRV32.DLL for 32 bit applications
Rem and WBTRCALL.DLL for 16 bit applications.
Rem
Rem You can run this program with Visual Basic 4.0 under Windows
3.1,
Rem Windows NT, or Windows 95.
Rem
Rem This example program creates a Btrieve file with 2 keys and
then
Rem does some insert and read operations on that file.
Rem
Rem Note about the Btrieve key buffer size: your key buffer should
Rem always be at least as large as the key buffer length parameter
Rem that you supply to Btrieve. If you indicate that your key
buffer
Rem is 10 bytes long and it is only 8, Btrieve may write past the
end
Rem of your key buffer when updating the key buffer with a key
value.
Rem Note that Btrieve returns a key value in the key buffer after
an
Rem 'insert' operation.
Rem
Rem *******************************************************************
Rem This sample code shows a workaround to the Visual Basic Long
variable
Rem type alignment problem. This problem, which manifests itself
as a
Rem status 29 on BCREATE operations with more than one index, as
an
Rem incorrect value for the total number of records in a BSTAT
operation,
Rem and as incorrect values for data being returned as Long
variable
Rem types, is a design limitation of Visual Basic.
Rem
Rem We workaround this structure member alignment issue by using a
User
Rem Defined Type. This workaround breaks the data into four (4)
units.
Rem Each unit is one (1) byte. Once the data has been returned
from the
Rem DLL (on BSTAT and in data), we use byte swapping and
conversion from
Rem Hexadecimal to Decimal to return the correct value.
Rem
Rem For more information about the Structure Member Alignment
issue,
Rem contact Microsoft or consult the VB4DLL.TXT file included with
Visual
Rem Basic.
Rem *******************************************************************
DefInt A-Z
Global Const BOPEN = 0
Global Const BCLOSE = 1
Global Const BINSERT = 2
Global Const BUPDATE = 3
Global Const BDELETE = 4
Global Const BGETEQUAL = 5
Global Const BGETNEXT = 6
Global Const BGETGREATEROREQUAL = 9
Global Const BGETFIRST = 12
Global Const BCREATE = 14
Global Const BSTAT = 15
Global Const BSTOP = 25
Global Const BVERSION = 26
Global Const BRESET = 28
Global Const KEY_BUF_LEN = 255
Rem Key Flags
Global Const DUP = 1
Global Const MODIFIABLE = 2
Global Const BIN = 4
Global Const NUL = 8
Global Const SEGMENT = 16
Global Const SEQ = 32
Global Const DEC = 64
Global Const SUP = 128
Rem Key Types
Global Const EXTTYPE = 256
Global Const MANUAL = 512
Global Const BSTRING = 0
Global Const BINTEGER = 1
Global Const BFLOAT = 2
Global Const BDATE = 3
Global Const BTIME = 4
Global Const BDECIMAL = 5
Global Const BNUMERIC = 8
Global Const BZSTRING = 11
Global Const BAUTOINC = 15
Declare Function BTRCALL Lib "w3btrv7.dll" (ByVal OP, ByVal Pb$, Db As
Any, DL As Integer, Kb As Any, ByVal Kl, ByVal Kn) As Integer
Rem ***************************************************************************
Rem Structures to overcome problems within Visual Basic.
Rem This User Defined Type allows us to convert the data coming in
from (or going to)
Rem our interface. By treating the data as a byte we can
concatenate the data back
Rem into a Long variable type without conversion problems.
Type typ_byte4
fld_Field1 As Byte
fld_Field2 As Byte
fld_Field3 As Byte
fld_Field4 As Byte
End Type
Rem ***************************************************************************
Rem Btrieve Structures
Type KeySpec
KeyPos As Integer
KeyLen As Integer
KeyFlags As Integer
KeyTot As typ_byte4
KeyType As String * 1
Reserved As String * 5
End Type
Type FileSpec
RecLen As Integer
PageSize As Integer
IndxCnt As Integer
NotUsed As String * 4
FileFlags As Integer
Reserved As String * 2
Allocation As Integer
KeyBuf0 As KeySpec
KeyBuf1 As KeySpec
End Type
Rem Note that due to the way Visual Basic 4.0 handles arrays of
user-
Rem defined types, the above type uses
Rem
Rem KeyBuf0 As KeySpec
Rem KeyBuf1 As KeySpec
Rem
Rem rather than
Rem
Rem KeyBuf(0 To 1) As KeySpec
Rem
Rem Each Key description must be a separate entry in the FileSpec.
Rem
Rem KeyBuf is treated similarly in 'StatFileSpecs', below.
Rem
Type StatFileSpecs
RecLen As Integer
PageSize As Integer
IndexTot As Integer
RecTot As typ_byte4
FileFlags As Integer
Reserved As String * 2
UnusedPages As Integer
KeyBuf0 As KeySpec
KeyBuf1 As KeySpec
End Type
Type btrDate
btrDay As Byte
btrMonth As Byte
btrYear As Integer
End Type
Global DateBuf As btrDate
Type RecordBuffer
Number As btrDate
Dummy As String * 26
End Type
Global FileBuf As FileSpec
Global DataBuf As RecordBuffer
Global StatFileBuffer As StatFileSpecs
Global PosBlk$
Global BufLen As Integer
Global DBLen As Integer
Type bytArr
f1(1 To 2) As Byte
End Type
Type VersionSpec
Major As Integer
Minor As Integer
EngType As Byte
End Type
Type VersionBuf
ClientVersion As VersionSpec
EngineVersion As VersionSpec
ServerVersion As VersionSpec
End Type
Type bytArr5
f1(1 To 5) As Byte
End Type
Type VersionBufArr
f1 As bytArr5
f2 As bytArr5
f3 As bytArr5
End Type
Public UserFileName As String
Declare Sub CopyMemory Lib "Kernel32" Alias "RtlMoveMemory" _
(Destination As Any, Source As Any, ByVal NumBytestoCopy As Long)
Sub GetBtrieveVersion()
'Stat Call
Dim VersionBuffer As VersionBuf
Dim VersionBufferArr As VersionBufArr
DBLen = Len(VersionBufferArr)
KeyBuffer$ = Space$(KEY_BUF_LEN)
KeyBufLen = KEY_BUF_LEN
Status = BTRCALL(BVERSION, PosBlk$, VersionBufferArr, DBLen, ByVal
KeyBuffer$, KeyBufLen, 0)
If Status <> 0 Then
msg$ = "Error in Stat Call. Status = " + Str$(Status)
PrintLB (msg$)
'GoTo Fini
Else
Dim VerTest As VersionBuf
CopyMemory VerTest.ClientVersion, VersionBufferArr.f1, 5
CopyMemory VerTest.EngineVersion, VersionBufferArr.f2, 5
CopyMemory VerTest.ServerVersion, VersionBufferArr.f3, 5
With VerTest
PrintLB ("Btrieve Client Version: " & .ClientVersion.Major & "." &
.ClientVersion.Minor & Chr$(.ClientVersion.EngType))
PrintLB ("Btrieve Engine Version: " & .EngineVersion.Major & "." &
.EngineVersion.Minor & " " & Chr$(.EngineVersion.EngType))
PrintLB ("Btrieve Server Version: " & .ServerVersion.Major & "." &
.ServerVersion.Minor & " " & Chr$(.ServerVersion.EngType))
End With
End If
End Sub
Sub PrintLB(Item As String)
BtrFrm32.List1.AddItem Item
End Sub
Sub RunTest()
PrintLB ("Btrieve Sample Test Started")
PrintLB ("")
Rem Local variables needed for conversion from byte to long.
Dim loc_RecTot As Long
Dim h_field1 As String
Dim h_field2 As String
Dim h_field3 As String
Dim h_field4 As String
Dim h_total As String
Rem **************************
FileName$ = "xface.btr"
PosBlk$ = Space$(128)
KeyBuffer$ = Space$(KEY_BUF_LEN)
Rem
Rem ***************** Btrieve Create *********************
Rem
Rem ************* SET UP FILE SPECS
FileBuf.RecLen = 30
FileBuf.PageSize = 1024
FileBuf.IndxCnt = 2
FileBuf.FileFlags = 0
Rem ************* SET UP KEY SPECS
FileBuf.KeyBuf0.KeyPos = 1
FileBuf.KeyBuf0.KeyLen = 4
FileBuf.KeyBuf0.KeyFlags = EXTTYPE + MODIFIABLE
FileBuf.KeyBuf0.KeyType = Chr$(BDATE)
FileBuf.KeyBuf1.KeyPos = 5
FileBuf.KeyBuf1.KeyLen = 26
FileBuf.KeyBuf1.KeyFlags = EXTTYPE + MODIFIABLE + DUP
FileBuf.KeyBuf1.KeyType = Chr$(BSTRING)
BufLen = Len(FileBuf)
KeyBufLen = Len(FileName$)
KeyBuffer$ = FileName$
Status = BTRCALL(BCREATE, PosBlk$, FileBuf, BufLen, ByVal KeyBuffer$,
KeyBufLen, 0)
If Status <> 0 Then
msg$ = "Error Creating File. Status = " + Str$(Status)
PrintLB (msg$)
Else
msg$ = "File XFACE.BTR Created Successfully!"
PrintLB (msg$)
End If
'Open File
KeyBufLen = KEY_BUF_LEN
KeyBuffer$ = FileName$
BufLen = Len(DataBuf)
KeyNum = 0
Status = BTRCALL(BOPEN, PosBlk$, DataBuf, BufLen, ByVal KeyBuffer$,
KeyBufLen, KeyNum)
If Status <> 0 Then
msg$ = "Error Opening file! " + Str$(Status)
PrintLB (msg$)
GoTo Fini
Else
msg$ = "File Opened Successfully!"
PrintLB (msg$)
End If
'Get Btrieve Version.
Call GetBtrieveVersion
Fini:
Status = BTRCALL(BRESET, PosBlk$, PatientVar, BufLen, KeyBuffer$,
KeyBufLen, KeyNum)
If Status Then
msg$ = "Error on B-Reset!" + Str$(Status)
PrintLB (msg$)
Else
msg$ = "BRESET okay."
PrintLB (msg$)
End If
Status = BTRCALL(BSTOP, PosBlk$, PatientVar, BufLen, KeyBuffer$,
KeyBufLen, KeyNum)
If Status Then
msg$ = "Error on B-Stop!" + Str$(Status)
PrintLB (msg$)
Else
msg$ = "BSTOP okay."
PrintLB (msg$)
End If
PrintLB ("")
PrintLB ("Btrieve Sample Test Completed")
End Sub
"Tim" <fox...@eaze.net> wrote in message news:<SjsV7.153$Qxo.19...@news2.randori.com>...
If you have ever written "old fashioned" programs which manipulated raw data
files, then moving to the Btrieve API is easy. In effect, you specify a block
of memory for the database to read or write -- and that is all it does for you.
If you're a "new-school" programmer who hasn't dabbled in the bits&bytes of
low-level memory or disk management, then learning Btrieve will be difficult,
unless you pick up one of the other tools, such as the ActiveX controls (a good
idea for VB developers).
In short, I can probably help get you up to speed with a one-on-one training
session, but this depends on the funds available for the project. I do have
another Pervasive developer series of open-enrollment courses coming up next
year, but not until mid-April.
If you have specific questions, post them here or let me know via EMail, and
I'll see what I can do to help get you started....