Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Posts
    3

    Unanswered: btrieve-Api and VB

    Hello,

    I call the btrieve API with Code 5 (get equal) from VB and I get the error number 21 if I use a key greater then 0.

    The size of the key buffer is great enouth, and if I use the key number 0 everything ist fine.

    The code is:

    KeyBuffer$ = "12345 "
    KeyBufLen = Len(KeyBuffer)
    keynum = KeyNumber
    BufLen = Len(DataBuf)
    Status = BTRCALL(pGetType, PosBlock, DataBuf, BufLen, ByVal KeyBuffer$, KeyBufLen, keynum)

    Thanx for help.

    Soner

  2. #2
    Join Date
    Dec 2001
    Posts
    1,109
    Provided Answers: 4
    This is because of the way VB passes strings to DLL functions. VB converts all strings to Unicode and so you end up with two bytes for every character. Btrieve is only expecting one byte. The way you work around this is to create UDTs for each of your key types and pass the UDT as the KeyBuffer for example:
    Code:
    'key struct for Key 0
    type typIdx0
      value as string * 6
    end type
    
    'key struct for Key 1
    type typIdx1
      ID as integer
    end type
    
    'key struct for Key 2
    type typIdx2
      somethingelse as string * 20
    end type
    Then when you want to issue the Get Equal (op code 5), you do something like:
    Code:
    dim KeyBuf0 as typIdx0
    KeyBuf0.value = "12345 "
    KeyBufLen = Len(KeyBuf0)
    keynum = KeyNumber
    BufLen = Len(DataBuf)
    Status = BTRCALL(pGetType, PosBlock, DataBuf, BufLen, ByVal KeyBuf, KeyBufLen, keynum)
    Mirtheil Software
    Certified Pervasive Developer
    Certified Pervasive Technician
    Custom Btrieve/VB development
    http://www.mirtheil.com
    I do not answer questions by email. Please post on the forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •