4 Replies - 730 Views - Last Post: 18 May 2011 - 12:24 PM Rate Topic: -----

#1 polens  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

question on how to Count how many days in a listbox?

Posted 16 May 2011 - 11:34 PM

so basically i have a textfile that is loaded into a listbox..
now i have to count the number of days in the listbox..
here is an example..

DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
10/08/2003;00:00:01;47;.1;.11;.111;.1111
11/08/2003;00:00:01;15125;.2;.22;.222;.2222
12/08/2003;00:00:01;15280;.3;.33;.333;.3333
13/08/2003;00:00:01;16554;.4;.44;.444;.4444
14/08/2003;00:00:01;11747;.5;.55;.555;.5555
15/08/2003;00:00:01;9840;.6;.66;.666;.6666
16/08/2003;00:00:01;9840;.7;.77;.777;.7777

i need to specifically count the number of days...
for this example it's 7(seven)
i tried this..
listbox1.items.contains(???)

but don't know exactly what to put in it...
EDIT
I manage to solved it please check if im on the right way..
 Dim i As Integer
        For Each item In ListBox1.Items
            If item.ToString.Contains(DateFormat.ShortDate) Then
                i = i + 1
            End If
        Next
        MsgBox(i)

This post has been edited by polens: 16 May 2011 - 11:43 PM


Is This A Good Question/Topic? 0
  • +

Replies To: question on how to Count how many days in a listbox?

#2 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: question on how to Count how many days in a listbox?

Posted 17 May 2011 - 12:35 AM

View Postpolens, on 16 May 2011 - 11:34 PM, said:

so basically i have a textfile that is loaded into a listbox..
now i have to count the number of days in the listbox..
here is an example..

DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
10/08/2003;00:00:01;47;.1;.11;.111;.1111
11/08/2003;00:00:01;15125;.2;.22;.222;.2222
12/08/2003;00:00:01;15280;.3;.33;.333;.3333
13/08/2003;00:00:01;16554;.4;.44;.444;.4444
14/08/2003;00:00:01;11747;.5;.55;.555;.5555
15/08/2003;00:00:01;9840;.6;.66;.666;.6666
16/08/2003;00:00:01;9840;.7;.77;.777;.7777

i need to specifically count the number of days...
for this example it's 7(seven)
i tried this..
listbox1.items.contains(???)

but don't know exactly what to put in it...
EDIT
I manage to solved it please check if im on the right way..
 Dim i As Integer
        For Each item In ListBox1.Items
            If item.ToString.Contains(DateFormat.ShortDate) Then
                i = i + 1
            End If
        Next
        MsgBox(i)


If you know that each item in your ListBox control is going to be a date (and it looks like that), why not just use ListBox1.Items.Count?
Was This Post Helpful? 0
  • +
  • -

#3 polens  Icon User is offline

  • D.I.C Head

Reputation: 13
  • View blog
  • Posts: 155
  • Joined: 09-November 09

Re: question on how to Count how many days in a listbox?

Posted 17 May 2011 - 12:43 AM

because the text file has this...DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
then it will also count it...
it can be done this way listbox1.items.count -1
but thats just cheating.. and anyways the problem is,
Calculate and display the number of days of currency data, e.g. for short.txt your program should display 7.

in the edited code, i can scan specifically a date type of string...i think...
so only the date can only be counted

This post has been edited by polens: 17 May 2011 - 12:45 AM

Was This Post Helpful? 0
  • +
  • -

#4 souptoy  Icon User is offline

  • D.I.C Head


Reputation: 54
  • View blog
  • Posts: 244
  • Joined: 17-January 08

Re: question on how to Count how many days in a listbox?

Posted 17 May 2011 - 08:04 AM

View Postpolens, on 17 May 2011 - 12:43 AM, said:

because the text file has this...DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
then it will also count it...
it can be done this way listbox1.items.count -1
but thats just cheating.. and anyways the problem is,
Calculate and display the number of days of currency data, e.g. for short.txt your program should display 7.

in the edited code, i can scan specifically a date type of string...i think...
so only the date can only be counted


First off, I don't know why listbox1.items.count - 1 is considered "cheating", let alone how your problem can be solved by subtracting your total count (in this case 7) by 1. You'll have to explain that one to me.

If I understand correctly, you have a text file that has records with columns DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX. If you read my original post, it has an assumption that is clearly stated:

Quote

If you know that each item in your ListBox control is going to be a date (and it looks like that)...


So, assuming each row of data in your text file that contains columns DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX is supposed to always have a date within it, then you don't need to "scan specifically a date type of string...so only the date can only be counted." You only need to count each row that is loaded. By the way, date type of string doesn't make sense.

I can see where my initial response could be confusing so I do apologize...it came off as sounding like each row would only be a date...not contain a date. It was late and after working two jobs, my wording may not have been completely accurate. Regardless, I stick to my initial counting solution.

On the other hand, if you need to actually do something with the dates besides output how many days of data there are, like calculate the difference between two dates, then yes...you need to extract those values.

Final caveat: if the date is not required in every row of your text file, then you are correct. However, that is not stated and it is assumed, for the sake of your example, that each row contains a date since each record in your text file contains a date.

My guess is that this is homework and it won't go that in depth. I could be wrong.

Final answer: you're on the right way but, in my opinion that you asked for, it could be done better. Hope that helps.
Was This Post Helpful? 0
  • +
  • -

#5 Keika  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 18-May 11

Re: question on how to Count how many days in a listbox?

Posted 18 May 2011 - 12:24 PM

View Postpolens, on 16 May 2011 - 11:34 PM, said:

so basically i have a textfile that is loaded into a listbox..
now i have to count the number of days in the listbox..
here is an example..

DATE;TIME;VOLUME;OPEN;CLOSE;MIN;MAX
10/08/2003;00:00:01;47;.1;.11;.111;.1111
11/08/2003;00:00:01;15125;.2;.22;.222;.2222
12/08/2003;00:00:01;15280;.3;.33;.333;.3333
13/08/2003;00:00:01;16554;.4;.44;.444;.4444
14/08/2003;00:00:01;11747;.5;.55;.555;.5555
15/08/2003;00:00:01;9840;.6;.66;.666;.6666
16/08/2003;00:00:01;9840;.7;.77;.777;.7777

i need to specifically count the number of days...
for this example it's 7(seven)
i tried this..
listbox1.items.contains(???)

but don't know exactly what to put in it...
EDIT
I manage to solved it please check if im on the right way..
 Dim i As Integer
        For Each item In ListBox1.Items
            If item.ToString.Contains(DateFormat.ShortDate) Then
                i = i + 1
            End If
        Next
        MsgBox(i)


I see that we are all knee deep into our major assignment!

Dude, you want to make things too complicated.

first, to ignore the first 2 lines of the file, use a line counter, that will count which line you're reading, if the counter is above 2 then display. Here's the trick, even if you don't display, a line is still read...

then within the if you use to display (another hint?!) use another counter to count the number of days... each line is one day, so if you keep adding 1 each line, you'll have the right number.

Good luck for the rest...

Keika
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1