Results 1 to 2 of 2

Thread: [2005] ?? Label Counting with Loops ??

  1. #1

    Thread Starter
    New Member hackmist's Avatar
    Join Date
    Nov 2007
    Posts
    7

    [2005] ?? Label Counting with Loops ??

    Here is my code. the lblProxyListCount.Text = cboProxies.SelectedIndex + 1 & " / " & cboProxies.Items.Count is not working until the loop is over, i want it to step through the count while the program is working. also the lblStatusBar.Text = "( Testing for working Proxies.... )" is not even showing either. Do labels not have precedence during a loop?


    Code:
      
      Private Sub btnTestProxies_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTestProxies.Click
            'connect to proxies in list, if connected successfully
            'add proxy to cboActiveProxies
            lblStatusBar.Text = "( Testing for working Proxies.... )"
    
            Dim sck As Socket = Nothing
            Dim i As Integer
            Dim IP As String = Split(cboProxies.Text, ":")(0)
            Dim Port As String = Split(cboProxies.Text, ":")(1)
    
            ' when proxies do not connect, nothing gets added to cboActiveProxies
            ' when test button is clicked lblStatusBar does not change text either
            ' its like labels are not taking any precedence
    
            On Error Resume Next
            For i = 0 To cboProxies.Items.Count - 1
                sck = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                sck.Connect(IP, Port)
                If sck.Connected Then
                    cboActiveProxies.Items.Add(cboProxies.Text)
                End If
                cboProxies.SelectedIndex = cboProxies.SelectedIndex + 1
                lblProxyListCount.Text = cboProxies.SelectedIndex + 1 & " / " & cboProxies.Items.Count
            Next i
    
            ' lblActiveProxiesCount.Text = cboActiveProxies.SelectedIndex + 1 & " / " & cboActiveProxies.Items.Count
            cboActiveProxies.SelectedIndex = 0
    
            sck.Close()
            tmrStatusBar.Enabled = True

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] ?? Label Counting with Loops ??

    If you are using a single thread then it's too busy running your loop to repaint the controls. Either use a worker thread to run the loop so the UI thread is free to repaint the controls or else call the Refresh method of a control after you change its content.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width