Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

extract bite array from buffer to output a literal string 1

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
Hi,

I have a custom function ("wSDBGetRecord" through a previous declare statment) that accesses an external custom database from within MS ACCESS. This function gets a specified record from a table within the external database and places the value within a BUFFER variable. I am having difficulty extracting a literal string from the binary data in the buffer.

I tried to assign the buffer to a byte array but it did not let me

wSDBGetRecord(iDBLink, iTBLink, FLG_KEY0, pRecord)
'pRecord is the BUFFER
abytTemp() = pRecord
strOutput = abytTemp()
lblCompanyName.Caption = Trim(strOutput)

I also tried the getSrting method but could not get it to work. Maybe I missed something.

Thnaks In advance
 
Perhaps this ?
lblCompanyName.Caption = Left(pRecord, InStr(pRecord, Chr(0)) - 1)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks for the fast reply.

I plugged your code in and got an error as follows:

"Compile Error:
Only User-defined types defined in public object modules can be coerced to or from a variant or passed to late-bound functions."

Jordan
 
How is declared (Dim'ed) pRecord ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I declared precord as follows.

Dim pRecord As buffer


It needs to be a Buffer because that is what the external database requires in order to pass the record information.
 
And what is buffer ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I thought buffer was a normal type within Access. The function is included in a SDK. The documentation says that the buffer recieves the retrieved record and the encoding of the external database appears to be ASCII. My guess is that is is a "holding" variable for the the data.

The following is the public declaration of the function in a module of hte access database:

Public Declare Function wSDBGetRecord Lib "C:\Program Files\Simply Accounting SDK\SDK\sa_dblyr.dll" (ByVal wDBLinkNo As Integer, ByVal wTBLinkNo As Integer, ByVal wKey As Integer, pRecord As buffer) As Integer
 
Search (Ctrl+F) the whole current project for buffer as I think it's a user defined type.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yeah, you were right,

here it is

Public Type buffer
Data(1999) As Byte
End Type
 
I have captured this data through:

pRecord.Data()

But I am not sure what I have. I want to turn it into a literal strong from the binary encoding.

Is there a way to do this?
 
A starting point:
Dim i As Integer, x As String
With pRecord
For i = 0 To UBound(.Data)
If .Data(i) = 0 Then Exit For
x = x & Chr(.Data(i))
Next
End With
Debug.Print "x='" & x & "'"


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The immediate window dispalys:

x=''

This is how I inserted your code. The declarations I put into the beginning of the procedure.

If wSDBOpenTable(iDBLink, "tCompany", FLG_READONLY, iTBLink) = DBS_SUCCESS Then
lId = 1
Call CopyMemory(pRecord.Data(0), lId, 150)
iRet = wSDBGetRecord(iDBLink, iTBLink, FLG_KEY0, pRecord)
If iRet = 0 Then
With pRecord
For i = 0 To UBound(.Data)
If .Data(i) = 0 Then Exit For
x = x & Chr(.Data(i))
Next
End With
End If
Debug.Print "x='" & x & "'"
lblCompanyName.Caption = x
End If
 
also, does it matter if it is UTF unicose or ACSII encoded?

thanks in advance
 
What is CopyMemory ?
Sorry, get rid of my last suggestion and go to the Simply Accounting SDK documentation.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Hello Again,

I have captured the array data from pRecord.Data through using StringFromGUID:

Code:
       Debug.Print pRecord.Data
       strOutput = StringFromGUID(pRecord.Data)
       Debug.Print strOutput

Here is what the Immediate window displayed:

Code:
'LINE 1
 ?l?????    ?????????                    ???????d                                          ????     ???a      ???            ???2???????8                 ???????1     ???????9                 ????? ?   ?????????                                                                                                                                        ????                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               
'LINE 2
{guid {00000001-0002-6250-3C01-4032100C5769}}

Do you know if the numbers captured by the array are encoding? Is there a process to turn these numbers into letters/numbers of a litteral string.

Thank You in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top