I'm trying very hard to make the VBA code work for the purpose of sending data to the gadget and once the data is processed by the gadget it is expected to come back and used as part of the sales invoice. The VBA code below is compiling no issue, the problem here is how to call the functions on the VBA onclick event:


VBA Main Function

Code:
Option Compare Database
Option Explicit

Public Const AF_INET = 2
Public Const SOCK_STREAM = 1
Public Const SOCKET_ERROR = 1
Public Const FD_SETSIZE = 64
Public Const FIONBIO = 2147772030#
Public Const SOCKADDR_IN_SIZE = 16
Public Const FORMAT_MESSAGE_FROM_SYSTEM = &H1000


Public Type WSADATA
    wVersion As Integer
    wHighVersion As Integer
    szDescription As String * 257
    szSystemStatus As String * 129
    iMaxSockets As Integer
    iMaxUdpDg As Integer
    lpVendorInfo As Long
End Type


Public Type SOCKADDR_IN
    sin_family As Integer
    sin_port As Integer
    sin_addr As Long
    sin_zero As String * 8
End Type


Public Type fd_set
    fd_count As Long
    fd_array(FD_SETSIZE) As Long
End Type


Public Type timeval
    tv_sec As Long
    tv_usec As Long
End Type


Public Declare PtrSafe Function WSAStartup Lib "wsock32.dll" (ByVal intVersionRequested As Integer, lpWSAData As WSADATA) As Long
Public Declare PtrSafe Function WSACleanup Lib "wsock32.dll" () As Long
Public Declare PtrSafe Function w_socket Lib "wsock32.dll" Alias "socket" (ByVal lngAf As Long, ByVal lngType As Long, ByVal lngProtocol As Long) As Long
Public Declare PtrSafe Function w_closesocket Lib "wsock32.dll" Alias "closesocket" (ByVal SocketHandle As Long) As Long
Public Declare PtrSafe Function w_bind Lib "wsock32.dll" Alias "bind" (ByVal socket As Long, Name As SOCKADDR_IN, ByVal namelen As Long) As Long
Public Declare PtrSafe Function w_connect Lib "wsock32.dll" Alias "connect" (ByVal socket As Long, Name As SOCKADDR_IN, ByVal namelen As Long) As Long
Public Declare PtrSafe Function w_send Lib "wsock32.dll" Alias "send" (ByVal socket As Long, buf As Any, ByVal length As Long, ByVal flags As Long) As Long
Public Declare PtrSafe Function w_recv Lib "wsock32.dll" Alias "recv" (ByVal socket As Long, buf As Any, ByVal length As Long, ByVal flags As Long) As Long
Public Declare PtrSafe Function w_select Lib "wsock32.dll" Alias "select" (ByVal nfds As Long, readfds As fd_set, writefds As fd_set, exceptfds As fd_set, timeout As timeval) As Long
Public Declare PtrSafe Function htons Lib "wsock32.dll" (ByVal hostshort As Integer) As Integer
Public Declare PtrSafe Function ntohl Lib "wsock32.dll" (ByVal netlong As Long) As Long
Public Declare PtrSafe Function inet_addr Lib "wsock32.dll" (ByVal Address As String) As Long
Public Declare PtrSafe Function ioctlsocket Lib "wsock32.dll" (ByVal socket As Long, ByVal Cmd As Long, argp As Long) As Long
Public Declare PtrSafe Function FormatMessage Lib "kernel32" Alias "FormatMessageA" (ByVal dwFlags As Long, lpSource As Any, ByVal dwMessageId As Long, ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long, Arguments As Long) As Long




Private Sub CloseSocket(socket As Long)
    If socket <> -1 Then
        w_closesocket socket
    End If
    WSACleanup
End Sub


Public Function VcitajURI(Address, URI)
    Dim ret As Long
    Dim SocketHandle As Long
    Dim wd As WSADATA
    Dim localAddress As SOCKADDR_IN
    Dim serverAddress As SOCKADDR_IN
    Dim URIRequest As String
    Dim retBuff(1000) As Byte
    Dim retString As String
    Dim tempString As String
    
    VcitajURI = ""
    SocketHandle = -1
    ret = WSAStartup(&H101, wd)
    If ret <> 0 Then GoTo ErrorHandler
    SocketHandle = w_socket(AF_INET, SOCK_STREAM, 0)
    If SocketHandle = -1 Then GoTo ErrorHandler
    localAddress.sin_family = AF_INET
    localAddress.sin_port = 0
    localAddress.sin_addr = 0
    ret = w_bind(SocketHandle, localAddress, SOCKADDR_IN_SIZE)
    If ret = -1 Then GoTo ErrorHandler
    serverAddress.sin_family = AF_INET
    serverAddress.sin_port = htons(80)
    serverAddress.sin_addr = inet_addr(Address)
    ret = w_connect(SocketHandle, serverAddress, SOCKADDR_IN_SIZE)
    If ret = -1 Then GoTo ErrorHandler
    URIRequest = "GET /" & URI & " HTTP/1.0" & vbCrLf & vbCrLf
    ret = w_send(SocketHandle, ByVal URIRequest, Len(URIRequest), 0)
    If ret = -1 Then GoTo ErrorHandler
    Do
        ret = w_recv(SocketHandle, retBuff(0), 1000, 0)
        If ret = -1 Then GoTo ErrorHandler
        If ret > 0 Then
            tempString = StrConv(retBuff, vbUnicode)
            retString = retString & Left(tempString, ret)
        End If
    Loop While ret > 0
    VcitajURI = retString
ErrorHandler:
    CloseSocket SocketHandle
End Function

Functions Required to be called in the subs procedures



Starting up Winsock

Code:
ret = WSAStartup(&H101, wd)

Code:
Private Sub StartOnclick()
?????????????
End Sub

Opening winsock


Code:
w_socket(AF_INET, SOCK_STREAM, 0)

Code:
Private sub OpeningOnclick()
???????????
End Sub

Binding the request information

Code:
w_bind(SocketHandle, localAddress, SOCKADDR_IN_SIZE)
Code:
Private Sub bindOnclick()
?????????????
End Sub

How to connect wins0ck

Code:
w_connect(SocketHandle, serverAddress, SOCKADDR_IN_SIZE)
Code:
Private Sub ConnectOnclick()
?????????????
End Sub

How to send data

Code:
w_send(SocketHandle, ByVal URIRequest, Len(URIRequest), 0)
Code:
Private Sub SendOnclick()
???????????????
End Sub
How receive data

Code:
w_recv(SocketHandle, retBuff(0), 1000, 0
)

Code:
Private Sub ReceiveOnclick()
????????????????
End Sub
That is where Im not able to connect properly.