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!

API trouble

Status
Not open for further replies.

jordanking

Programmer
Sep 8, 2005
351
Hello,

I am having difficulty working with an API that is not from windows, but from another supplied library. These API's work to convert between binary coded decimal numbers and long data type in VBA. They are used specifically in regards to date and time in the following two formats:
0YYYYMMDD Year/mobth/day
or
0HHMMSSHH hou(12 hour clock/minute/second/hundredths)

I have delared the following API's in a seperate module

Code:
Public Type Buffer
    Data(1999) As Byte
End Type

Public Declare Function pLongToBcd Lib "C:\Program Files\Simply Accounting SDK\SDK\sa_dblyr.dll" (ByRef pNumber As Buffer, ByVal lValue As Long, ByVal nLength As Integer) As Buffer

Public Declare Function lBcdToLong Lib "C:\Program Files\Simply Accounting SDK\SDK\sa_dblyr.dll" (ByRef fBCD As Buffer, ByVal nLength As Integer) As Long

Buffer is basiclly just a byte data type 2000 bytes in length.

I have no problem using the "lBcdToLong function. It works and returns no errors.

I have a big problem with "pLongToBcd". Every time i try to use it, I not only get a code break, but it instantly shuts access down. Full crash.

I discovered that you cannot pass user defined variables with "ByVal" and tried to remove the "ByRef" all together. Still crashing. It also breaks regardleess of whether the number matches the proper date format or not.

Here is an example of a siimple use of the function "pLongToBCD" that causes a crash.

Code:
Private Sub cmdTest1_Click()

Dim lngTemp As Long
Dim pDate As Buffer
Dim pTemp As Buffer
Dim strTemp As String
Dim strDay As String
Dim strMonth As String
Dim strYear As String
Dim strBCDdt As String
Dim lngBCDdt As Long

lngTemp = CLng(20051225)
strTemp = CStr(date)
strDay = Mid(strTemp, 1, 2)
strMonth = Mid(strTemp, 4, 2)
strYear = Mid(strTemp, 7, 4)
strBCDdt = strYear & strMonth & strDay
lngBCDdt = CLng(strBCDdt)

Debug.Print Trim(lngBCDdt)
pTemp = pLongToBcd(pTemp, lngBCDdt, 5)

End Sub

The following is the API documentation that I have.
lBcdToLong
Definition long lBcdToLong(LPBYTE pNumber, WORD nLength)

Description lBcdToLong converts a BCD number to a long value.

Parameters:
pNumber A pointer to the BCD number to be converted.
nLength The length of the BCD value.
Returns The converted value.

pLongToBcd
Definition LPBYTE pLongToBcd(LPBYTE pNumber, long lValue, WORD nLength)

Description pLongToBcd converts a long value to a BCD number.

Parameters:
pNumber A pointer to the converted value.
lValue The long value to be converted.
nLength The length of the BCD value.
Returns The converted value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top