Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need some help - ListBox Counter
#1
I've coded an application which allows people to import a list of usernames, and check whether or not they are available on the website Habbo Hotel.

What I want to do though, is add a counter at the bottom (a Label), which displays the number of accounts that have been tested. This is a really simple task but I can't for the life of me work out how to do it, as I haven't coded anything for a long time..

Here is my current code:
Code:
For Each fn As String In ListBox1.Items
            Try
                Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://habbo.com/home/" & fn)
                Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
            Catch Ex As Exception
                RichTextBox1.AppendText((Chr(10) & fn))
            End Try
        Next
        Label1.Text = "Done"

Thanks.
Reply
#2
Can anybody help me out with this?
Reply
#3
Add a label named label2 and change its default text to "0". The use this code:
Code:
For Each fn As String In ListBox1.Items
             Try
                 Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://habbo.com/home/" & fn)
                 Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
             Catch Ex As Exception
                 RichTextBox1.AppendText((Chr(10) & fn))
             Finally
                 Label2.Text=CStr(CDbl(Label2.Text)+1)
             End Try
         Next
         Label1.Text = "Done"
My software company: Porosis Software
Games: Terrantula
Apps: Mathanasis, ColorGrabber
Reply
#4
Nice one mate thanks for that, works a charm!
Reply
#5
i also need that thanks thanasis2028 it works
[Image: 0b0033.gif]
Reply
#6
For Each fn As String In ListBox1.Items
Try
Dim myDatabuffer As Byte() = myWebClient.DownloadData("http://habbo.com/home/" & fn)
Dim download As String = Encoding.ASCII.GetString(myDatabuffer)
Catch Ex As Exception
RichTextBox1.AppendText((Chr(10) & fn))
Finally
Label2.Text=CStr(CDbl(Label2.Text)+1)
End Try
Next
Label1.Text = "Done"
Should work
Reply
#7
Why are you all using loops for this, it will only slow down the application for such a simple task, all you need is this:
Code:
ListBox1.Items.Count
Define that as whatever you want, and place that outcome/value wherever you want.

lol... If you had over 1000 entries, your methods would cause the application to render unresponsive, and crash. I'd like to see a coders group here soon so that more people can become educated with all different programming languages out there. It would be nice on this forum I think Smile

Reply
#8
The For Each loop isn't there for the counter, it is there to go through each item in the ListBox control.
The counter is just additional, so people know the status of the scan.
Reply
#9
Quote:What I want to do though, is add a counter at the bottom (a Label), which displays the number of accounts that have been tested

I only saw the mention of numbers there, but i'm confused now, You want the label to display every item in the list? or the label to display the count of the list?

Either way you should have a download buffer to download in chunks (a specified number of bytes,) whatever your program is trying to download. It will keep your program from locking up and becoming unresponsive from bigger data downloads.
Reply
#10
(07-03-2011, 04:03 AM)Ace Wrote: I only saw the mention of numbers there, but i'm confused now, You want the label to display every item in the list? or the label to display the count of the list?

Either way you should have a download buffer to download in chunks (a specified number of bytes,) whatever your program is trying to download. It will keep your program from locking up and becoming unresponsive from bigger data downloads.

thanasis2028's code worked for counting each item in the list that had been "scanned".

The program doesn't lock up or freeze as it's running through a background worker. It's actually surprisingly quick.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  TextBox2.Text | Transfer Text to ListBox Die 3 2,375 01-02-2012, 06:09 PM
Last Post: AceInfinity
  [VB.NET] - ListBox Drag & Drop - [TUT] Fragma 10 6,939 08-25-2011, 07:02 PM
Last Post: AceInfinity
  [How To] Remove Duplicates From A Listbox PURP 6 6,415 05-12-2011, 02:31 PM
Last Post: PURP
  Listbox Help Danny 8 2,999 04-18-2010, 12:37 AM
Last Post: RaZoR03
  Save Listbox Danny 5 2,095 04-18-2010, 12:35 AM
Last Post: RaZoR03

Forum Jump:


Users browsing this thread: 1 Guest(s)