If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Pervasive.SQL > btrieve-Api and VB

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-18-03, 16:12
akasus akasus is offline
Registered User
 
Join Date: Nov 2003
Posts: 3
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
Reply With Quote
  #2 (permalink)  
Old 11-18-03, 17:54
mirtheil mirtheil is offline
Registered User
 
Join Date: Dec 2001
Posts: 1,026
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On