• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Making the form update info while in a loop

I have a ping program that I created from some example code.  I can't seem to make it update the progress on the form while it is inside this loop.  I would also like to be able to click a button on the form to cancel this loop, but the program acts locked up until it finishes this loop.  See below.  

For IPloop = intIP4 To intIP5
      txtipaddress = intIP1 & "." & intIP2 & "." & intIP3 & "." & IPloop
      If SocketsInitialize() Then
        'ping the ip passing the address, text
        'to send, and the ECHO structure.
        success = Ping(txtipaddress, "Test", ECHO)
        'display the results
        If chkDifferentWindow.Value = Unchecked Then
          If success = 0 Or chkDisplayResults.Value = Checked Then
            PingOutput.SelStart = 65535
            If chkHostname.Value = Unchecked Then
              PingOutput.SelText = txtipaddress + GetStatusCode(success) + Chr$(13) + Chr$(10)
            Else
              If success = 0 Then
                PingOutput.SelText = txtipaddress + "  " + GetHostNameFromIP(txtipaddress) + Chr$(13) + Chr$(10)
              Else
                PingOutput.SelText = txtipaddress + "  " + GetStatusCode(success) + Chr$(13) + Chr$(10)
              End If
            End If
          End If
        Else
        If success = 0 Then
          PingOutput.SelStart = 65535
          If chkHostname.Value = Unchecked Then
            PingOutput.SelText = txtipaddress + GetStatusCode(success) + Chr$(13) + Chr$(10)
          Else
            PingOutput.SelText = txtipaddress + "  " + GetHostNameFromIP(txtipaddress) + Chr$(13) + Chr$(10)
          End If
        Else
          pingOutput2.SelStart = 65535
          pingOutput2.SelText = txtipaddress + GetStatusCode(success) + Chr$(13) + Chr$(10)
        End If
      End If
      SocketsCleanup
    Else
      MsgBox "Windows Sockets for 32 bit Windows " & "environments is not successfully responding."
    End If
    Next IPloop
0
Tom_Hickerson
Asked:
Tom_Hickerson
1 Solution
 
aikimarkCommented:
after changing a property of a control on the form, such as label.caption or textbox.text, you should do a me.refresh.

You would also do well to include a DoEvents statement along with the update.

Instead of doing this update for every iteration, you might only do the update every N iterations.  For this use
If (IPLoop Mod N) = 0 Then
  'form update statements
End If
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now