Announcement

Collapse
No announcement yet.

Btrieve 32-bit Declare?

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

  • Btrieve 32-bit Declare?

    Code:
    'This is a translation of a sample from 
    'Visual Basic to Power Basic.
    'It compiles fine, but receives an error 11
    '(invalid file name) creating the file.
    
    'Does someone have the correct DECLARE statement?
    
    #COMPILE EXE
    #REGISTER NONE
    #DIM ALL
    
    'Original declare in VB
    DECLARE FUNCTION BTRCALL LIB "wbtrv32.dll" (BYVAL OP%,_
                                                BYVAL Pb$,_
                                                Db AS ANY,_
                                                DL AS INTEGER,_
                                                Kb AS ANY,_
                                                BYVAL Kl%,_
                                                BYVAL Kn%) AS INTEGER
    
    
    DECLARE SUB PrintLb(Msg AS STRING)
    '  Operation Codes
    '===========================================================================
    %BOPEN              = 0
    %BCLOSE             = 1
    %BINSERT            = 2
    %BUPDATE            = 3
    %BDELETE            = 4
    %BGETEQUAL          = 5
    %BGETNEXT           = 6
    %BGETPREV           = 7
    %BGETGREATER        = 8
    %BGETGE             = 9
    %BGETLESS           = 10
    %BGETLE             = 11
    %BGETFIRST          = 12
    %BGETLAST           = 13
    %BCREATE            = 14
    %BSTAT              = 15
    %BGETPOSITION       = 22
    %BGETDIRECT         = 23
    %BSTEPNEXT          = 24
    %BSTOP              = 25
    %BVERSION           = 26
    %BUNLOCK            = 27
    %BRESET             = 28
    %BSTEPFIRST         = 33
    %BSTEPLAST          = 34
    %BSTEPPREV          = 35
    %BGETPERCENT        = 44
    %BFINDPERCENT       = 45
    %BLOCK              = 100
    
    %KEY_BUF_LEN = 255
    
    REM  Key Flags
    %DUP = 1
    %MODIFIABLE = 2
    %BIN = 4
    %NUL = 8
    %SEGMENT = 16
    %SEQ = 32
    %DEC = 64
    %SUP = 128
    
    REM  Key Types
    %EXTTYPE = 256
    %MANUAL = 512
    %BSTRING = 0
    %BINTEGER = 1
    %BFLOAT = 2
    %BDATE = 3
    %BTIME = 4
    %BDECIMAL = 5
    %BNUMERIC = 8
    %BZSTRING = 11
    %BAUTOINC = 15
    
    REM ***************************************************************************
    
    REM  Btrieve Structures
    
    Type KeySpec
              KeyPos    AS INTEGER
              KeyLen    AS INTEGER
              KeyFlags  AS INTEGER
            ' KeyTot    AS LONG    'may not be in version 5
              NotUse    AS STRING * 4
              KeyType   AS STRING * 1
              NullValue AS STRING * 1
              Reserved  AS STRING * 4
    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
    
    Type StatFileSpecs
         RecLen              AS INTEGER
         PageSize            AS INTEGER
         IndexTot            AS INTEGER
         RecTot              AS LONG
         FileFlags           AS INTEGER
         Reserved            AS STRING * 2
         UnusedPages         AS INTEGER
         KeyBuf0             AS KeySpec
         KeyBuf1             AS KeySpec
    END Type
    
    Type RecordBuffer
             Number           AS DOUBLE
             Dummy            AS STRING * 26
    END Type
    
    Type VersionBuf
        Major AS INTEGER
        Minor AS INTEGER
        Engine AS STRING * 1
    END Type
    
    GLOBAL FileBuf AS FileSpec
    GLOBAL DataBuf AS RecordBuffer
    GLOBAL StatFileBuffer AS StatFileSpecs
    GLOBAL PosBlk AS STRING
    GLOBAL BufLen AS INTEGER
    GLOBAL DBLen AS INTEGER
    
    SUB RunTest()
        PRINTLB "Btrieve Test Started"
    
    REM **************************
    DIM FilName AS STRING
    DIM KeyBuffer AS STRING
    DIM KeyBufLen AS INTEGER
    DIM KeyNumber AS INTEGER
    DIM Stat AS INTEGER
    DIM Msg AS STRING
    DIM KeyNum AS INTEGER
    DIM x AS LONG
    DIM count AS LONG
    DIM KBuf#
    
    
    DIM PatientVar AS STRING 'unsure about this dummy variable
    FILNAME$ = "TEST.BTR"
    
    PosBlk = SPACE$(128)
    KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
    
    REM
    REM ***************** Btrieve CREATE *********************
    REM
    
    REM ************* SET UP FILE SPECS
    FileBuf.RecLen = 34
    FileBuf.PageSize = 1024
    FileBuf.IndxCnt = 2
    FileBuf.FileFlags = 0
    
    REM ************* SET UP KEY SPECS
    FileBuf.KeyBuf0.KeyPos = 1
    FileBuf.KeyBuf0.KeyLen = 8
    FileBuf.KeyBuf0.KeyFlags = %EXTTYPE + %MODIFIABLE +%DUP
    FileBuf.KeyBuf0.KeyType = CHR$(%BFLOAT)
    
    FileBuf.KeyBuf1.KeyPos = 9
    FileBuf.KeyBuf1.KeyLen = 26
    FileBuf.KeyBuf1.KeyFlags = %EXTTYPE + %MODIFIABLE + %DUP
    FileBuf.KeyBuf1.KeyType = CHR$(%BSTRING)
    
    BufLen = LEN(FileBuf)
    KeyBufLen = LEN(FILNAME$)
    KeyBuffer$ = FILNAME$
    
    PRINT "Values before create call:
    PRINT "Operation    "%BCREATE
    PRINT "PosBlk len   ";LEN(PosBlk)
    PRINT "FileBufLen   ";LEN(FileBuf)
    PRINT "BufLen       ";Buflen
    PRINT "KeyBuffer$   ";KeyBuffer$
    PRINT "keyBufferlen ";LEN(KeyBuffer$)
    PRINT "KeyBufLen    ";keyBufLen
    
    Stat = BTRCALL(BYVAL %BCREATE,   _
                   BYVAL  PosBlk,    _
                     FileBuf,  _
                      BufLen,  _
                  KeyBuffer$,  _
                    BYVAL KeyBufLen, _
                    BYVAL KeyNumber)
    PRINT
    PRINT "Values after create call:
    PRINT "Operation    "%BCREATE
    PRINT "PosBlk len   ";LEN(PosBlk)
    PRINT "FileBufLen   ";LEN(FileBuf)
    PRINT "BufLen       ";Buflen
    PRINT "KeyBuffer$   ";KeyBuffer$
    PRINT "keyBufferlen ";LEN(KeyBuffer$)
    PRINT "KeyBufLen    ";keyBufLen
    
    IF Stat <> 0 THEN
        Msg$ = "Error Creating File. Stat = " + STR$(Stat)
        PrintLB Msg$ + " press any key"
        EXIT SUB
    ELSE
        Msg$ = "File " + FilName + " Created Successfully!"
        PrintLB (Msg$)
    END IF
    
    'Open File
    KeyBufLen = %KEY_BUF_LEN
    KeyBuffer$ = FILNAME$
    BufLen = LEN(DataBuf)
    KeyNum = 0
    
    Stat = BTRCALL(%BOPEN, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
    
    IF Stat <> 0 THEN
        Msg$ = "Error Opening file! " + STR$(Stat)
        PrintLB (Msg$)
        GOTO Fini
    ELSE
        Msg$ = "File Opened Succesfully!"
        PrintLB (Msg$)
    END IF
    
    FOR x = 1 TO 3
    'yr = 1992
    'mo = 1
    'dy = 1
    DataBuf.Number = 1  'was dateserial (yr,no,dy)
    BufLen = LEN(DataBuf)
    KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
    KeyBufLen = %KEY_BUF_LEN
    DataBuf.Dummy = "Record" + STR$(x)
    
    Stat = BTRCALL(%BINSERT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
        Msg$ = "Error on Insert. " + STR$(Stat)
        PrintLB (Msg$)
    ELSE
        Count = Count + 1
        Msg$ = "Insert Record " + STR$(Count)
        PrintLB (Msg$)
    END IF
    
    NEXT
    
    'Get First Record
    BufLen = LEN(DataBuf)
    KeyBuffer$ = SPACE$(255)
    KeyBufLen = %KEY_BUF_LEN
    
    Stat = BTRCALL(%BGETFIRST, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
        Msg$ = "Error on BGETFIRST. " + STR$(Stat)
        PrintLB (Msg$)
    ELSE
        'Msg$ = "BGETFIRST okay for : " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
        Msg$ = "BGETFIRST okay for : " + STR$(DataBuf.Number) + DataBuf.Dummy
        PrintLB (Msg$)
    END IF
    
    'Get Next Record
    BufLen = LEN(DataBuf)
    KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
    KeyBufLen = %KEY_BUF_LEN
    
    Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
        Msg$ = "Error on BGETNEXT. " + STR$(Stat)
        PrintLB (Msg$)
    ELSE
        'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
        Msg$ = "BGETNEXT okay for: " + STR$(DataBuf.Number) + DataBuf.Dummy
        PrintLB (Msg$)
    END IF
    
    'Get Next Record
    BufLen = LEN(DataBuf)
    KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
    KeyBufLen = %KEY_BUF_LEN
    
    Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
        Msg$ = "Error on BGETNEXT. " + STR$(Stat)
        PrintLB (Msg$)
    ELSE
        'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
        Msg$ = "BGETNEXT okay for: " + STR$(DataBuf.Number) + DataBuf.Dummy
        PrintLB (Msg$)
    END IF
    
    'Get Equal
    BufLen = LEN(DataBuf)
    KBuf# = 1
    KeyBufLen = 8
    
    Stat = BTRCALL(%BGETEQUAL, PosBlk, DataBuf, BufLen, KBuf#, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
        Msg$ = "Error on Get Equal. Stat = " + STR$(Stat)
        PrintLB (Msg$)
    ELSE
        PrintLB ("BGETEQUAL okay on following key: " + STR$(DataBuf.Number))
    END IF
    
    'Stat Call
    DBLen = LEN(StatFileBuffer)
    KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
    KeyBufLen = %KEY_BUF_LEN
    
    Stat = BTRCALL(%BSTAT, PosBlk, StatFileBuffer, DBLen, KeyBuffer$, KeyBufLen, 0)
    
    IF Stat <> 0 THEN
      Msg$ = "Error in Stat Call. Stat = " + STR$(Stat)
      PrintLB (Msg$)
      GOTO Fini
    ELSE
        Msg = "Records + STR$(StatFileBuffer.RecTot)
        PrintLB (Msg)
    END IF
    
    Fini:
    Stat = BTRCALL(%BRESET, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
    
    IF Stat THEN
        Msg$ = "Error on B-Reset!" + STR$(Stat)
        PrintLB (Msg$)
    ELSE
       Msg$ = "BRESET okay."
       PrintLB (Msg$)
    END IF
    
    Stat = BTRCALL(%BSTOP, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
    
    IF Stat THEN
       Msg$ = "Error on B-Stop!" + STR$(Stat)
        PrintLB (Msg$)
    ELSE
       Msg$ = "BSTOP okay."
       PrintLB (Msg$)
    END IF
    PrintLB ("")
    PrintLB ("Btrieve Sample Test Completed")
    
    END SUB
    SUB PrintLb(Msg AS STRING)
       PRINT Msg
    END SUB
    
    FUNCTION PBMAIN AS LONG
       RunTest
       WAITKEY$
    END FUNCTION
    ------------------

  • #2
    Btrieve engines always want the filename in ASCIIZ format (trailing null). Add a CHR$(0) to your filename and your program gets past the status 11 on the open..... there are other problems with your program however, your data buffer length on the create is wrong and you'll be getting status 22's instead.



    ------------------
    --
    Steve Ryckman
    mailto:[email protected][email protected]</A>
    http://the.nevets.net
    --
    Steve Ryckman, VP Technical Services
    Security Information & Management Systems, Inc.
    mailto:[email protected][email protected]</A>
    http://www.simsware.com

    Comment


    • #3
      Works for me with btrieve 6.xx / 7.xx (Translation of the Pervasive C header)
      Code:
      Declare Function BTRCALL Lib "wbtrv32.dll" Alias "BTRCALL"  (ByVal Word, _   'Operation to perform
                                                                   Asciiz, _       'Position block
                                                                   Any, _          'Databuffer
                                                                   Integer, _      'Databuffer length
                                                                   Any, _          'Keybuffer
                                                                   ByVal Byte, _   'Keylength
                                                                   ByVal Byte) _   'Keynumber
                                                                   As Integer      '
      ------------------
      Peter.
      mailto[email protected][email protected]</A>
      Regards,
      Peter

      "Simplicity is a prerequisite for reliability"

      Comment


      • #4
        'Changed the declare and increased the buflen
        'and still get error 11 - invalid file name.
        'Again, this is a translation of the VB code that
        'comes with Btrieve that works in Visual Basic 6.
        'Definitely missing something here.

        'Can anyone get this to run?

        Code:
        #COMPILE EXE
        #REGISTER NONE
        #DIM ALL
        
        'Original declare in VB
        'DECLARE FUNCTION BTRCALL LIB "wbtrv32.dll" (BYVAL OP%,_
        '                                            BYVAL Pb$,_
        '                                            Db AS ANY,_
        '                                            DL AS INTEGER,_
        '                                            Kb AS ANY,_
        '                                            BYVAL Kl%,_
        '                                            BYVAL Kn%) AS INTEGER
        
        DECLARE FUNCTION BTRCALL LIB "wbtrv32.dll" _
                               (BYVAL OP AS WORD,_     'operation to perform
                                Pb AS ASCIIZ,_         'Position block
                                Db AS ANY,_            'Databuffer
                                DL AS INTEGER,_        'Databuffer length
                                Kb AS ANY,_            'Keybuffer
                   BYVAL KeyLength AS BYTE,_           'KeyLength
                   BYVAL KeyNumber AS BYTE)_           'KeyNumber
                                   AS INTEGER
                                                    
         
        DECLARE SUB PrintLb(Msg AS STRING)
        '  Operation Codes
        '===========================================================================
        %BOPEN              = 0
        %BCLOSE             = 1
        %BINSERT            = 2
        %BUPDATE            = 3
        %BDELETE            = 4
        %BGETEQUAL          = 5
        %BGETNEXT           = 6
        %BGETPREV           = 7
        %BGETGREATER        = 8
        %BGETGE             = 9
        %BGETLESS           = 10
        %BGETLE             = 11
        %BGETFIRST          = 12
        %BGETLAST           = 13
        %BCREATE            = 14
        %BSTAT              = 15
        %BGETPOSITION       = 22
        %BGETDIRECT         = 23
        %BSTEPNEXT          = 24
        %BSTOP              = 25
        %BVERSION           = 26
        %BUNLOCK            = 27
        %BRESET             = 28
        %BSTEPFIRST         = 33
        %BSTEPLAST          = 34
        %BSTEPPREV          = 35
        %BGETPERCENT        = 44
        %BFINDPERCENT       = 45
        %BLOCK              = 100
        
        %KEY_BUF_LEN = 64
        
        REM  Key Flags
        %DUP = 1
        %MODIFIABLE = 2
        %BIN = 4
        %NUL = 8
        %SEGMENT = 16
        %SEQ = 32
        %DEC = 64
        %SUP = 128
        
        REM  Key Types
        %EXTTYPE = 256
        %MANUAL = 512
        %BSTRING = 0
        %BINTEGER = 1
        %BFLOAT = 2
        %BDATE = 3
        %BTIME = 4
        %BDECIMAL = 5
        %BNUMERIC = 8
        %BZSTRING = 11
        %BAUTOINC = 15
        
        REM ***************************************************************************
        
        REM  Btrieve Structures
        
        Type KeySpec
                  KeyPos    AS INTEGER
                  KeyLen    AS INTEGER
                  KeyFlags  AS INTEGER
                  NotUsed   AS LONG        '(KeyTot& is not in version 5
                  KeyType   AS STRING * 1
                  NullValue AS STRING * 1
                  Reserved  AS STRING * 4
        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
        
        Type StatFileSpecs
             RecLen              AS INTEGER
             PageSize            AS INTEGER
             IndexTot            AS INTEGER
             RecTot              AS LONG
             FileFlags           AS INTEGER
             Reserved            AS STRING * 2
             UnusedPages         AS INTEGER
             KeyBuf0             AS KeySpec
             KeyBuf1             AS KeySpec
        END Type
        
        Type RecordBuffer
                 Number           AS DOUBLE
                 Dummy            AS STRING * 26
        END Type
        
        Type VersionBuf
            Major AS INTEGER
            Minor AS INTEGER
            Engine AS STRING * 1
        END Type
        
        GLOBAL FileBuf AS FileSpec
        GLOBAL DataBuf AS RecordBuffer
        GLOBAL StatFileBuffer AS StatFileSpecs
        GLOBAL PosBlk AS ASCIIZ * 129
        GLOBAL BufLen AS INTEGER
        GLOBAL DBLen AS INTEGER
        
        SUB RunTest()
            PRINTLB "Btrieve Test Started"
        
        REM **************************
        DIM FilName AS STRING
        DIM KeyBuffer AS STRING
        DIM KeyBufLen AS INTEGER
        DIM KeyNumber AS INTEGER
        DIM Stat AS INTEGER
        DIM Msg AS STRING
        DIM KeyNum AS INTEGER
        DIM x AS LONG
        DIM count AS LONG
        DIM KBuf#
        
        
        DIM PatientVar AS STRING 'unsure about this dummy variable
        FILNAME$ = "TEST.BTR"
        PosBlk = SPACE$(128)
        KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
        
        REM
        REM ***************** Btrieve CREATE *********************
        REM
        
        REM ************* SET UP FILE SPECS
        FileBuf.RecLen = 34
        FileBuf.PageSize = 1024
        FileBuf.IndxCnt = 2
        FileBuf.FileFlags = 0
        
        REM ************* SET UP KEY SPECS
        FileBuf.KeyBuf0.KeyPos = 1
        FileBuf.KeyBuf0.KeyLen = 8
        FileBuf.KeyBuf0.KeyFlags = %EXTTYPE + %MODIFIABLE +%DUP
        FileBuf.KeyBuf0.KeyType = CHR$(%BFLOAT)
        
        FileBuf.KeyBuf1.KeyPos = 9
        FileBuf.KeyBuf1.KeyLen = 26
        FileBuf.KeyBuf1.KeyFlags = %EXTTYPE + %MODIFIABLE + %DUP
        FileBuf.KeyBuf1.KeyType = CHR$(%BSTRING)
        
        KeyBufLen = %Key_Buf_Len
        KeyBuffer$ = SPACE$(KeyBufLen)
        LSET KeyBuffer$ = FILNAME$
        BufLen = 256
        
        
        PRINT "Values before create call:
        PRINT "Operation    "%BCREATE
        PRINT "PosBlk len   ";LEN(PosBlk)
        PRINT "FileBufLen   ";LEN(FileBuf)
        PRINT "BufLen       ";Buflen
        PRINT "KeyBuffer$    ";KeyBuffer$
        PRINT "KeyBufLen    ";keyBufLen
        
        Stat = BTRCALL(BYVAL %BCREATE,   _
                         PosBlk,         _
                         FileBuf,        _
                          BufLen,        _
                      KeyBuffer$,        _
                        BYVAL KeyBufLen, _
                        BYVAL KeyNumber)
        PRINT
        PRINT "Values after create call:
        PRINT "Operation    "%BCREATE
        PRINT "PosBlk len   ";LEN(PosBlk)
        PRINT "FileBufLen   ";LEN(FileBuf)
        PRINT "BufLen       ";Buflen
        PRINT "KeyBuffer$    ";KeyBuffer$
        PRINT "KeyBufLen    ";keyBufLen
        
        IF Stat <> 0 THEN
            Msg$ = "Error Creating File. Stat = " + STR$(Stat)
            PrintLB Msg$ + " press any key"
            EXIT SUB
        ELSE
            Msg$ = "File " + FilName + " Created Successfully!"
            PrintLB (Msg$)
        END IF
        
        'Open File
        KeyBufLen = %KEY_BUF_LEN
        KeyBuffer$ = FILNAME$
        BufLen = LEN(DataBuf)
        KeyNum = 0
        
        Stat = BTRCALL(%BOPEN, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
        
        IF Stat <> 0 THEN
            Msg$ = "Error Opening file! " + STR$(Stat)
            PrintLB (Msg$)
            GOTO Fini
        ELSE
            Msg$ = "File Opened Succesfully!"
            PrintLB (Msg$)
        END IF
        
        FOR x = 1 TO 3
        'yr = 1992
        'mo = 1
        'dy = 1
        DataBuf.Number = 1  'was dateserial (yr,no,dy)
        BufLen = LEN(DataBuf)
        KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
        KeyBufLen = %KEY_BUF_LEN
        DataBuf.Dummy = "Record" + STR$(x)
        
        Stat = BTRCALL(%BINSERT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
            Msg$ = "Error on Insert. " + STR$(Stat)
            PrintLB (Msg$)
        ELSE
            Count = Count + 1
            Msg$ = "Insert Record " + STR$(Count)
            PrintLB (Msg$)
        END IF
        
        NEXT
        
        'Get First Record
        BufLen = LEN(DataBuf)
        KeyBuffer$ = SPACE$(255)
        KeyBufLen = %KEY_BUF_LEN
        
        Stat = BTRCALL(%BGETFIRST, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
            Msg$ = "Error on BGETFIRST. " + STR$(Stat)
            PrintLB (Msg$)
        ELSE
            'Msg$ = "BGETFIRST okay for : " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
            Msg$ = "BGETFIRST okay for : " + STR$(DataBuf.Number) + DataBuf.Dummy
            PrintLB (Msg$)
        END IF
        
        'Get Next Record
        BufLen = LEN(DataBuf)
        KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
        KeyBufLen = %KEY_BUF_LEN
        
        Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
            Msg$ = "Error on BGETNEXT. " + STR$(Stat)
            PrintLB (Msg$)
        ELSE
            'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
            Msg$ = "BGETNEXT okay for: " + STR$(DataBuf.Number) + DataBuf.Dummy
            PrintLB (Msg$)
        END IF
        
        'Get Next Record
        BufLen = LEN(DataBuf)
        KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
        KeyBufLen = %KEY_BUF_LEN
        
        Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
            Msg$ = "Error on BGETNEXT. " + STR$(Stat)
            PrintLB (Msg$)
        ELSE
            'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
            Msg$ = "BGETNEXT okay for: " + STR$(DataBuf.Number) + DataBuf.Dummy
            PrintLB (Msg$)
        END IF
        
        'Get Equal
        BufLen = LEN(DataBuf)
        KBuf# = 1
        KeyBufLen = 8
        
        Stat = BTRCALL(%BGETEQUAL, PosBlk, DataBuf, BufLen, KBuf#, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
            Msg$ = "Error on Get Equal. Stat = " + STR$(Stat)
            PrintLB (Msg$)
        ELSE
            PrintLB ("BGETEQUAL okay on following key: " + STR$(DataBuf.Number))
        END IF
        
        'Stat Call
        DBLen = LEN(StatFileBuffer)
        KeyBuffer$ = SPACE$(%KEY_BUF_LEN)
        KeyBufLen = %KEY_BUF_LEN
        
        Stat = BTRCALL(%BSTAT, PosBlk, StatFileBuffer, DBLen, KeyBuffer$, KeyBufLen, 0)
        
        IF Stat <> 0 THEN
          Msg$ = "Error in Stat Call. Stat = " + STR$(Stat)
          PrintLB (Msg$)
          GOTO Fini
        ELSE
            Msg = "Records + STR$(StatFileBuffer.RecTot)
            PrintLB (Msg)
        END IF
        
        Fini:
        Stat = BTRCALL(%BRESET, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
        
        IF Stat THEN
            Msg$ = "Error on B-Reset!" + STR$(Stat)
            PrintLB (Msg$)
        ELSE
           Msg$ = "BRESET okay."
           PrintLB (Msg$)
        END IF
        
        Stat = BTRCALL(%BSTOP, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
        
        IF Stat THEN
           Msg$ = "Error on B-Stop!" + STR$(Stat)
            PrintLB (Msg$)
        ELSE
           Msg$ = "BSTOP okay."
           PrintLB (Msg$)
        END IF
        PrintLB ("")
        PrintLB ("Btrieve Sample Test Completed")
        
        END SUB
        SUB PrintLb(Msg AS STRING)
           PRINT Msg
        END SUB
        
        FUNCTION PBMAIN AS LONG
           RunTest
           WAITKEY$
        END FUNCTION

        _




        ------------------

        Comment


        • #5
          Peter,
          You got it to work with your headers?
          Mike

          ------------------

          Comment


          • #6
            Mike, off the top of my head, the position block should be either As Any or as Asciiz - not a byval string. The easiest thing to do would be to create a 128 byte asciiz and pass it.

            If you're interested there's a 32-bit btrieve wrapper DLL available for free download on my web site.
            www.basicguru.com/dickinson

            The source is available for the asking - send me a private email to request it - [email protected]

            The full declares for 32-bit btrieve are in the source code.

            Best Regards,
            Don

            ------------------
            Don Dickinson
            www.greatwebdivide.com

            Comment


            • #7
              Don,
              I tried using a 128-byte asciiz string and
              alot of other combinations. This code
              works in Visual Basic "as is" so I'm thinking
              it could be the word alignment in the structure.
              I can access records ok, but the create is
              the problem with error 11 (invalid file name.)
              I've place code before and after the call to
              see if anything changes. The position block
              changes in length from 128 to 124 bytes using len.
              I've tried passing filname + chr$(0), etc.
              I have sent you a private e-mail requesting the source.
              Thanks again,
              Mike
              mailto:[email protected][email protected]</A>

              ------------------


              [This message has been edited by Mike Doty (edited November 26, 2000).]

              Comment


              • #8
                Yes, I realize this isn't DOS, the disussion is about 32 bit stuff.

                For what it may be worth in PB 3.5 for DOS ... here is a general
                sample of what works for a raw create segment sample in 6.15:

                Code:
                BTFCREATE: ' Btrieve create function 14
                        BFunc%(Bfile%) = 14 '                   BCREATE%
                        DBuflen% =  16 + (18) * 16 ' FileHam.RecLen ' Set to buffer length
                        KeyBuffer$ = BFname(Bfile%) '           Set to name of file
                        KeyNumber% = 0 '                        Set to record number key
                        Test$ = "" '                            Null holding string
                        MEMPACK '                               Pack memory
                        Test$ = MKI$(Fham(Bfile%).RecLen1) + _ '        Record length
                                MKI$(Fham(Bfile%).PageSize1) + _ '      Page size
                                MKI$(Fham(Bfile%).IndxCnt1) + "0000" + _ '      Index count
                                MKI$(Fham(Bfile%).FileFlags1) + "00" + "00" ' File flags
                           FOR NP% = 0 TO (18) '                        For all known extra ke
                             Test$ = Test$ + MKI$(Fham(Bfile%).KeyHam.Kdx(NP%).KeyPos) + _
                             MKI$(Fham(Bfile%).KeyHam.Kdx(NP%).KeyLen) + _
                             MKI$(Fham(Bfile%).KeyHam.Kdx(NP%).KeyFlags) + "0000" + _
                             Fham(Bfile%).KeyHam.Kdx(NP%).KeyType + "000" + _
                             RIGHT$(MKI$(NP%), 1) + "0"
                           NEXT NP%
                           DEF SEG = VARSEG(Dham(Bfile%)) '     Get Seg of Buffer
                           DMY% = LEN(Test$) '                  Determine length
                           NN% = 0 '                            Start at zero
                           FOR VJ& = VARPTR(Dham(Bfile%)) TO VARPTR(Dham(Bfile%)) + DMY% - 1
                             NN% = NN% + 1 '                    Add a step
                             POKE VJ&, ASC(MID$(Test$, NN%, 1))  '      Put byte value here
                           NEXT VJ&
                        DEF SEG '                               Return to original segment
                        CALL BTRVFAR() '                        BTRVFAR:
                           IF Bstatus% <> 0 THEN
                              GOSUB BXPRTERR '                  Print error
                           ELSE
                              PRINT "File Created Successfully!"
                           END IF
                        RETURN '                                What do we do next
                If someone can suggest any way to clean it up I'd gladly do it.
                It was Don and a couple others who got me going a long time ago.
                Don't even get started on the MEMPACK deal in the snip. It was one
                of the gimmicks I discovered that stabilized my large programs
                that, somehow kept variables from irregularly showing up with what
                shouldn't ever be there. As long as it is there previous to the
                poke, things never seem to go wrong. Take it out, and sometimes
                what goes in and out of the call itself just isn't there where it
                is supposed to be. I use many such files. They have worked
                perfectly now ever since I stuffed it in there, but failed very
                irregularly before and when I take it out, so I just always leave
                one in there before the POKE routines...

                Anyway, if I don't one way or another, at least here, initiate
                that part of memory that is to be used, I get an error (24) during
                the CREATE function in 6.15...

                FWIW .. if it helps ..

                ------------------
                Mike Luther
                [email protected]
                Mike Luther
                [email protected]

                Comment


                • #9
                  The working version of Mike's example:
                  Code:
                  #Compile Exe
                  #Register None
                  #Dim All
                  
                  'Original declare in VB
                  Declare Function BTRCALL Lib "wbtrv32.dll" (ByVal Word,_
                                                              Asciiz,_
                                                              Any,_
                                                              Integer,_
                                                              Any,_
                                                              ByVal Byte,_
                                                              ByVal Byte) As Integer
                  
                  
                  Declare Sub PrintLb(Msg As String)
                  '  Operation Codes
                  '===========================================================================
                  %BOPEN              = 0
                  %BCLOSE             = 1
                  %BINSERT            = 2
                  %BUPDATE            = 3
                  %BDELETE            = 4
                  %BGETEQUAL          = 5
                  %BGETNEXT           = 6
                  %BGETPREV           = 7
                  %BGETGREATER        = 8
                  %BGETGE             = 9
                  %BGETLESS           = 10
                  %BGETLE             = 11
                  %BGETFIRST          = 12
                  %BGETLAST           = 13
                  %BCREATE            = 14
                  %BSTAT              = 15
                  %BGETPOSITION       = 22
                  %BGETDIRECT         = 23
                  %BSTEPNEXT          = 24
                  %BSTOP              = 25
                  %BVERSION           = 26
                  %BUNLOCK            = 27
                  %BRESET             = 28
                  %BSTEPFIRST         = 33
                  %BSTEPLAST          = 34
                  %BSTEPPREV          = 35
                  %BGETPERCENT        = 44
                  %BFINDPERCENT       = 45
                  %BLOCK              = 100
                  
                  %KEY_BUF_LEN = 255
                  
                  Rem  Key Flags
                  %DUP = 1
                  %MODIFIABLE = 2
                  %BIN = 4
                  %NUL = 8
                  %SEGMENT = 16
                  %SEQ = 32
                  %DEC = 64
                  %SUP = 128
                  
                  Rem  Key Types
                  %EXTTYPE = 256
                  %MANUAL = 512
                  %BSTRING = 0
                  %BINTEGER = 1
                  %BFLOAT = 2
                  %BDATE = 3
                  %BTIME = 4
                  %BDECIMAL = 5
                  %BNUMERIC = 8
                  %BZSTRING = 11
                  %BAUTOINC = 15
                  
                  Rem ***************************************************************************
                  
                  Rem  Btrieve Structures
                  
                  Type KeySpec
                            KeyPos    As Integer
                            KeyLen    As Integer
                            KeyFlags  As Integer
                            Reserved1 As String * 4
                            KeyType   As String * 1
                            Reserved2 As String * 5
                  End Type
                  
                  Type FileSpec
                           RecLen             As Integer
                           PageSize           As Integer
                           IndxCnt            As Integer
                           Reserved1          As String * 4
                           FileFlags          As Integer
                           DupPtrs            As Byte
                           Reserved2          As String * 1
                           Allocation         As Integer
                           KeyBuf(1)          As KeySpec
                  End Type
                  
                  Type StatFileSpecs
                       RecLen              As Integer
                       PageSize            As Integer
                       IndexTot            As Integer
                       RecTot              As String * 4
                       FileFlags           As Integer
                       Reserved            As String * 2
                       UnusedPages         As Integer
                       KeyBuf(1)           As KeySpec
                  End Type
                  
                  Type RecordBuffer
                           Number           As Double
                           Dummy            As String * 26
                  End Type
                  
                  Type VersionBuf
                      Major   As Integer
                      Minor   As Integer
                      Engine  As String * 1
                      Major1  As Integer
                      Minor1  As Integer
                      Engine1 As String * 1
                      Major2  As Integer
                      Minor2  As Integer
                      Engine2 As String * 1
                  End Type
                  
                  Global FileBuf          As FileSpec
                  Global DataBuf          As RecordBuffer
                  Global StatFileBuffer   As StatFileSpecs
                  Global PosBlk           As Asciiz * 129
                  Global BufLen           As Integer
                  Global DBLen            As Integer
                  
                  Sub RunTest()
                      PRINTLB "Btrieve Test Started"
                  
                  Rem **************************
                  Dim FilName         As String
                  Dim KeyBuffer       As Asciiz * %KEY_BUF_LEN + 1
                  Dim KeyBufLen       As Byte
                  Dim KeyNumber       As Integer
                  Dim Stat            As Integer
                  Dim Msg             As String
                  Dim KeyNum          As Integer
                  Dim x               As Long
                  Dim count           As Long
                  Dim KBuf#
                  
                  
                  Dim PatientVar As String 'unsure about this dummy variable
                  FILNAME$ = "TEST.BTR"
                  
                  PosBlk = Space$(128)
                  KeyBuffer$ = Space$(%KEY_BUF_LEN)
                  
                  Rem
                  Rem ***************** Btrieve Create *********************
                  Rem
                  
                  Rem ************* Set Up FILE SPECS
                  FileBuf.RecLen          = 34
                  FileBuf.PageSize        = 1024
                  FileBuf.IndxCnt         = 2
                  FileBuf.FileFlags       = 0
                  
                  Rem ************* Set Up KEY SPECS
                  FileBuf.KeyBuf(0).KeyPos  = 1
                  FileBuf.KeyBuf(0).KeyLen  = 8
                  FileBuf.KeyBuf(0).KeyFlags= %EXTTYPE + %MODIFIABLE + %DUP
                  FileBuf.KeyBuf(0).KeyType = Chr$(%BFLOAT)
                  
                  FileBuf.KeyBuf(1).KeyPos  = 9
                  FileBuf.KeyBuf(1).KeyLen  = 26
                  FileBuf.KeyBuf(1).KeyFlags= %EXTTYPE + %MODIFIABLE + %DUP
                  FileBuf.KeyBuf(1).KeyType = Chr$(%BSTRING)
                  
                  BufLen                  = Len(FileBuf)
                  KeyBuffer               = FilName
                  KeyBufLen               = Len(KeyBuffer)
                  
                  Print "Values before create call:
                  Print "Operation    "%BCREATE
                  Print "PosBlk len   ";Len(PosBlk)
                  Print "FileBufLen   ";Len(FileBuf)
                  Print "BufLen       ";Buflen
                  Print "KeyBuffer$   ";KeyBuffer$
                  Print "keyBufferlen ";Len(KeyBuffer$)
                  Print "KeyBufLen    ";keyBufLen
                  
                  Stat = BTRCALL(%BCREATE,   _
                                  PosBlk,    _
                                  FileBuf,  _
                                  BufLen,  _
                                  KeyBuffer,  _
                                  KeyBufLen, _
                                  0)
                  Print
                  Print "Values after create call:
                  Print "Operation    "%BCREATE
                  Print "PosBlk len   ";Len(PosBlk)
                  Print "FileBufLen   ";Len(FileBuf)
                  Print "BufLen       ";Buflen
                  Print "KeyBuffer$   ";KeyBuffer$
                  Print "keyBufferlen ";Len(KeyBuffer$)
                  Print "KeyBufLen    ";keyBufLen
                  
                  If Stat <> 0 Then
                      Msg$ = "Error Creating File. Stat = " + Str$(Stat)
                      PrintLB Msg$ + " press any key"
                      Exit Sub
                  Else
                      Msg$ = "File " + FilName + " Created Successfully!"
                      PrintLB (Msg$)
                  End If
                  
                  'Open File
                  KeyBufLen = %KEY_BUF_LEN
                  KeyBuffer$ = FILNAME$
                  BufLen = Len(DataBuf)
                  KeyNum = 0
                  
                  Stat = BTRCALL(%BOPEN, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error Opening file! " + Str$(Stat)
                      PrintLB (Msg$)
                      GoTo Fini
                  Else
                      Msg$ = "File Opened Succesfully!"
                      PrintLB (Msg$)
                  End If
                  
                  For x = 1 To 3
                  'yr = 1992
                  'mo = 1
                  'dy = 1
                  DataBuf.Number = 1  'was dateserial (yr,no,dy)
                  BufLen = Len(DataBuf)
                  KeyBuffer$ = Space$(%KEY_BUF_LEN)
                  KeyBufLen = %KEY_BUF_LEN
                  DataBuf.Dummy = "Record" + Str$(x)
                  
                  Stat = BTRCALL(%BINSERT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error on Insert. " + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                      Count = Count + 1
                      Msg$ = "Insert Record " + Str$(Count)
                      PrintLB (Msg$)
                  End If
                  
                  Next
                  
                  'Get First Record
                  BufLen = Len(DataBuf)
                  KeyBuffer$ = Space$(255)
                  KeyBufLen = %KEY_BUF_LEN
                  
                  Stat = BTRCALL(%BGETFIRST, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error on BGETFIRST. " + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                      'Msg$ = "BGETFIRST okay for : " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
                      Msg$ = "BGETFIRST okay for : " + Str$(DataBuf.Number) + DataBuf.Dummy
                      PrintLB (Msg$)
                  End If
                  
                  'Get Next Record
                  BufLen = Len(DataBuf)
                  KeyBuffer$ = Space$(%KEY_BUF_LEN)
                  KeyBufLen = %KEY_BUF_LEN
                  
                  Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error on BGETNEXT. " + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                      'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
                      Msg$ = "BGETNEXT okay for: " + Str$(DataBuf.Number) + DataBuf.Dummy
                      PrintLB (Msg$)
                  End If
                  
                  'Get Next Record
                  BufLen = Len(DataBuf)
                  KeyBuffer$ = Space$(%KEY_BUF_LEN)
                  KeyBufLen = %KEY_BUF_LEN
                  
                  Stat = BTRCALL(%BGETNEXT, PosBlk, DataBuf, BufLen, KeyBuffer$, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error on BGETNEXT. " + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                      'Msg$ = "BGETNEXT okay for: " + STR$(Year(DataBuf.Number)) + DataBuf.Dummy
                      Msg$ = "BGETNEXT okay for: " + Str$(DataBuf.Number) + DataBuf.Dummy
                      PrintLB (Msg$)
                  End If
                  
                  'Get Equal
                  BufLen = Len(DataBuf)
                  KBuf# = 1
                  KeyBufLen = 8
                  
                  Stat = BTRCALL(%BGETEQUAL, PosBlk, DataBuf, BufLen, KBuf#, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                      Msg$ = "Error on Get Equal. Stat = " + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                      PrintLB ("BGETEQUAL okay on following key: " + Str$(DataBuf.Number))
                  End If
                  
                  'Stat Call
                  DBLen = Len(StatFileBuffer)
                  KeyBuffer$ = Space$(%KEY_BUF_LEN)
                  KeyBufLen = %KEY_BUF_LEN
                  
                  Stat = BTRCALL(%BSTAT, PosBlk, StatFileBuffer, DBLen, KeyBuffer$, KeyBufLen, 0)
                  
                  If Stat <> 0 Then
                    Msg$ = "Error in Stat Call. Stat = " + Str$(Stat)
                    PrintLB (Msg$)
                    GoTo Fini
                  Else
                      Msg = "Records + STR$(StatFileBuffer.RecTot)
                      PrintLB (Msg)
                  End If
                  
                  Fini:
                  Stat = BTRCALL(%BRESET, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
                  
                  If Stat Then
                      Msg$ = "Error on B-Reset!" + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                     Msg$ = "BRESET okay."
                     PrintLB (Msg$)
                  End If
                  
                  Stat = BTRCALL(%BSTOP, PosBlk, PatientVar, BufLen, KeyBuffer$, KeyBufLen, KeyNum)
                  
                  If Stat Then
                     Msg$ = "Error on B-Stop!" + Str$(Stat)
                      PrintLB (Msg$)
                  Else
                     Msg$ = "BSTOP okay."
                     PrintLB (Msg$)
                  End If
                  PrintLB ("")
                  PrintLB ("Btrieve Sample Test Completed")
                  
                  End Sub
                  Sub PrintLb(Msg As String)
                     Print Msg
                  End Sub
                  
                  Function PbMain As Long
                     RunTest
                     'Sleep 1000
                     WaitKey$
                  End Function
                  
                  '------------------
                  ------------------
                  Peter.
                  mailto[email protected][email protected]</A>



                  [This message has been edited by Peter Lameijn (edited November 27, 2000).]
                  Regards,
                  Peter

                  "Simplicity is a prerequisite for reliability"

                  Comment


                  • #10
                    Peter,
                    It works great. I'm going to keep
                    working in Btrieve 5.10 and 6.15
                    because the routines in DOS are
                    now identical to the Windows routines!

                    Don,
                    Thanks for the Btrieve routines.
                    They will definitely be used!



                    ------------------

                    Comment


                    • #11
                      Hi Mike,
                      I've emailed you the source. If you're getting an 11 be very careful that you aren't using a long file name for a database and that it's not in a long filename directory and that it's on a mapped drive (not UNC - you need a drive letter). Btrieve is very, very, very, very picky about these things. Pretend you're using a DOS computer and you'll be fine (no long or UNC anything). There might be ways to make it work with long file names, UNC, etc, but if you want it to work every time, don't use them.
                      Per the VB code, it won't work as-is in powerbasic because PB treats ByVal strings differently than VB.
                      Best Regards,
                      Don

                      Originally posted by Mike Doty:
                      Don,
                      I tried using a 128-byte asciiz string and
                      alot of other combinations. This code
                      works in Visual Basic "as is" so I'm thinking
                      it could be the word alignment in the structure.
                      I can access records ok, but the create is
                      the problem with error 11 (invalid file name.)
                      I've place code before and after the call to
                      see if anything changes. The position block
                      changes in length from 128 to 124 bytes using len.
                      I've tried passing filname + chr$(0), etc.
                      I have sent you a private e-mail requesting the source.
                      Thanks again,
                      Mike
                      mailto:[email protected][email protected]</A>



                      ------------------
                      Don Dickinson
                      www.greatwebdivide.com

                      Comment

                      Working...
                      X