GetChunk Method, StateChanged Event Example

The example uses the GetChunk method in the StateChanged event to retrieve a chunk of data. The example uses a Select Case statement to determine what to do with every possible state. The example assumes a TextBox control named txtData exists on the form.

Private Sub Inet1_StateChanged(ByVal State As Integer)
   ' Retrieve server response using the GetChunk 
   ' method when State = 12. This example assumes the
   ' data is text.

   Select Case State
   ' ... Other cases not shown.

   Case icResponseReceived ' 12
      Dim vtData As Variant ' Data variable.
      Dim strData As String: strData = ""
      Dim bDone As Boolean: bDone = False

      ' Get first chunk.
      vtData = Inet1.GetChunk(1024, icString)
      DoEvents
      Do While Not bDone
         strData = strData & vtData
         DoEvents
         ' Get next chunk.
         vtData = Inet1.GetChunk(1024, icString)
         If Len(vtData) = 0 Then
            bDone = True
         End If
      Loop

      txtData.Text = strData
   End Select
   
End Sub