Papa_Bear1
Member
- Local time
- Today, 11:49
- Joined
- Feb 28, 2020
- Messages
- 137
I'm trying to do something very much like @nectorch references in their post:
("Challenges with Ms Access VBA with socket programming", at https://www.access-programmers.co.u...ms-access-vba-with-socket-programming.318926/).
I've made it through a few hurdles with the earliest steps of starting up winsock, and connecting and opening a socket, getting a socket ID, and sending the 1st "send" command (which in my case happens to be JSON-formatted). Those steps appear to be working now. I'm now stuck on the "recv" command causing Access to just crash and close.
The reference used (Agilent-sourced examples intended for Excel it seems...) has a "RecvAscii" routine (...shown below, but with my comments added...) where they retrieve values - apparently one character at a time - which I'm not expecting to need to do - but - it should work regardless - right? Anyway - it crashes on the first time it tries to run the "count = Recv(socketId, c, 1, 0) line.
I've tried opening up the c variable to not be restricted to one character - no dice.
I've tried using a different dll that I happened to see in a different source/reference (ws2_32.dll rather than wsock32.dll) - no dice.
Curious if anyone has experienced this or has any advice.
("Challenges with Ms Access VBA with socket programming", at https://www.access-programmers.co.u...ms-access-vba-with-socket-programming.318926/).
I've made it through a few hurdles with the earliest steps of starting up winsock, and connecting and opening a socket, getting a socket ID, and sending the 1st "send" command (which in my case happens to be JSON-formatted). Those steps appear to be working now. I'm now stuck on the "recv" command causing Access to just crash and close.
The reference used (Agilent-sourced examples intended for Excel it seems...) has a "RecvAscii" routine (...shown below, but with my comments added...) where they retrieve values - apparently one character at a time - which I'm not expecting to need to do - but - it should work regardless - right? Anyway - it crashes on the first time it tries to run the "count = Recv(socketId, c, 1, 0) line.
I've tried opening up the c variable to not be restricted to one character - no dice.
I've tried using a different dll that I happened to see in a different source/reference (ws2_32.dll rather than wsock32.dll) - no dice.
Curious if anyone has experienced this or has any advice.
Code:
Function RecvAscii(dataBuf As String, ByVal MaxLength As Integer) As Integer
Dim c As String * 1
Dim length As Integer
Dim count As Long
'---------------------------------------------------------------------------------------
'This routine came from the Agilent document example code for Excel, and they read
' in one character at a time, looking for a Line-Feed character to know they're done.
'The "c" variable, that the character is read into, was dimensioned to a fixed length
' of one for this reason.
'---------------------------------------------------------------------------------------
'---------------------------------------------------------------------------------------
'Initialize.
dataBuf = ""
'---------------------------------------------------------------------------------------
'Begin process of cycling through reading values from the socket.
While length < MaxLength
DoEvents
'Read one character at a time.
count = Recv(socketId, c, 1, 0)
'Check if error occurred.
'(Not sure why this is not specifically checking for -1.)
If count < 1 Then
RecvAscii = RECV_ERROR
dataBuf = Chr$(0)
Exit Function
End If
'Check if we are done (LF character)
If c = Chr$(10) Then
dataBuf = dataBuf + Chr$(0)
RecvAscii = NO_ERROR
Exit Function
End If
'Concatenate and move on.
length = length + count
dataBuf = dataBuf + c
Wend
'---------------------------------------------------------------------------------------
'If we made it to here, then something went wrong.
RecvAscii = RECV_ERROR
End Function
Last edited: