' This runs whenever "something happens" in the Inet2 control.
' For explanation, click one of the Inet controls on the form
' and press F1.  Then read the example for the StateChanged Event.
Private Sub Inet2_StateChanged(ByVal State As Integer)
    Dim ResponseStruct As WDDXStruct 'WDDX-style structure object
    Dim Received, Updated, Inserted As Integer


    ' What "State" did the control just change to?
    ' (Connected, Receiving, Finished, Error, etc
    Select Case State


    ' If the state of the control is icError (11)
    Case icError
      MsgBox ("An error occurred while posting data to the webserver.")


    ' If state of control is "Finished Successfully" (12)
    Case icResponseCompleted  ' 12
        Dim Chunk As Variant ' Data variable.
        Dim strData As String: strData = ""
        Dim bDone As Boolean: bDone = False

        ' Pull first "chunk" of data from control's "buffer"
        Chunk = Inet2.GetChunk(1024, icString)
        DoEvents

        ' Until we have extracted all data from control's buffer...
        Do While Not bDone

            ' Append the Chunk to the strData variable,
            ' Then pull the next chunk from buffer
            strData = strData & Chunk
            Chunk = Inet2.GetChunk(1024, icString)
            DoEvents

            ' If the just-pulled chunk is empty, we're done
            If Len(Chunk) = 0 Then
                bDone = True
            End If
        Loop


        ' Extract Response "Structure" from recieved packet
        Set ResponseStruct = MyDeser.deserialize(strData)

        ' Use Structure to set Received, Updated, Inserted vars
        ' Then discard the Response Structure
        Received = ResponseStruct.getProp("RECEIVED")
        Updated = ResponseStruct.getProp("UPDATED")
        Inserted = ResponseStruct.getProp("INSERTED")
        Set ResponseStruct = Nothing


        ' Display "Done" message to user
        MsgBox ("Records sent to server: " & Received & vbCr _
          & "Records inserted: " & Inserted & vbCr _
          & "Records updated: " & Updated)


    ' If state of Inet2 control is not "Finished Successfully"
    Case Else
      DoEvents

    End Select

End Sub
