Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc
Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.ScFlag for Zambia

asked on 

How to call a Function in Ms Access with bytes

I want to call the function below in a sub in Ms Access , how do I do it:

Function RecvAryReal(dataBuf() As Double) As Long
Dim x As Long
' this are special function for byte array doings
' if we want to delimeter the code
' this helps us then complex communication with
' the enc28j60 connected µC device


    ' receive DOS format 64bit binary data


    Dim buf As String * 20
    Dim size As Long
    Dim length As Long
    Dim count As Long
    ' this is special for communicate with
    ' OSZ or other devices later
    ' .. ;-)
    Dim recvBuf(25616) As Byte
   
    ' receive header info "ROY<##"
    ' we can setup here our Startcode too
    ' but we do this in the "worker makro later"
    x = recv(socketId, buf, 8, 0)
   
    size = Val(Mid$(buf, 3, 6))
   
    count = 0
    length = 0
    Do While length < size
        DoEvents
        count = recvB(socketId, recvBuf(length), size - length, 0)
        If (count > 0) Then
            length = length + count
        End If
    Loop
   
    ' receive ending LF
    count = recv(socketId, buf, 1, 0)
   
    ' copy recieved data to Single type array dataBuf()
    CopyMemory dataBuf(LBound(dataBuf)), recvBuf(0), length
    'dataBuf = recvBuf
   
    RecvAryReal = length / 8
   
End Function



Open in new window

Microsoft Access

Avatar of undefined
Last Comment
ste5an
Avatar of aikimark
aikimark
Flag of United States of America image

Try this:
BufLen = RecvAryReal(myDataArray)

Open in new window

Avatar of Hankwembo Christopher,FCCA,FZICA,CIA,MAAT,B.A.Sc

ASKER

Ok kindly see the error below:


User generated image
Avatar of ste5an
ste5an
Flag of Germany image

Function RecvAryReal(dataBuf() As Double) As Long

Open in new window

VBA does not do a type conversion in this case. You need to pass the necessary array instead of a string.
I have tried it this way still it says the same thing:

Dim strData As Byte

Open in new window

Avatar of aikimark
aikimark
Flag of United States of America image

It expects and array of type double
Avatar of ste5an
ste5an
Flag of Germany image

The signature as already posted of that function is

Function RecvAryReal(dataBuf() As Double) As Long

Open in new window

You must pass an array of double.
You must pass an array of double.

Kindly give us an example of how to pass the array of double????????????/
Do you mean to do it like below:

Private Sub CmdCread_Click()
On Error GoTo Err_Handler
Dim db As DAO.Database
Dim Rs As DAO.Recordset
Dim x As Long
Dim p As Long
Dim n As Long
Dim strData() As Double
Dim json As Object
Dim Details As Variant
Dim Z As Long
Dim strFindata As String
Dim strDataAudit As String
p = RecvAryReal(strData)


n = FreeFile()
Open "C:\Users\chris.hankwembo\Desktop\WinTesting\Test.txt" For Output As #n
Print #n, ShowHex(RecvAryReal(strData))
Close #n
MsgBox "strData:" & vbCrLf & ShowHex(RecvAryReal(strData))

Open in new window

Dim strData() As Double
p = RecvAryReal(strData)

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ste5an
ste5an
Flag of Germany image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo