Results 1 to 10 of 10

Thread: Adding Times In List Boxes

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    38

    Adding Times In List Boxes

    I currently have a list box which displays the length of an item. I.e.
    2.23
    8.12
    2.05
    6.14
    3.11

    In a second list box next to it I want to display the start time of each item if they were to be run sequentially. I.e.
    2.23 0.00
    8.12 2.23
    2.05 10.35
    6.14 16.49
    3.11 20.00

    How would I achieve this?

  2. #2
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    how are you calculating the (what I assume to be) the execution time of the different parts? GetTickCount? I would have seperate variables for each part and have one that starts over and one that keeps counting.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    38
    They are just strings added to the list box from a combo box

  4. #4
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    soo... you don't actually calculate them?

    If not, you could just add them together as you add them to the first list box and keep adding that time to the other listbox.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  5. #5

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    38
    You'll have to forgive me, I'm a new user to VB. Yes your right. However, I will eventually need to move items up and down the list box so the each start time will need to recalculated everytime a move is made. Am I making sense?

  6. #6
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    Yes, you are making sense.

    You are going to have to make a routine, that whenever the first listbox is changed, that the second listbox will automatically update with some kind of algorithm. And it will be fairly simple. All you have to do is start at the top with the static "0.00" and then look at the first listbox and add #1 and #2 to get the second listing in the second listbox.

    You'll have to simply look at the upper bound of the first listbox and loop through it until you reach the end... add 2 at a time, store that value in the second listbox, then move on with that time and the time of the next length...

    I think you understand the logic of what I'm saying... probably just not the coding. You'll want to access the "List" object of the listbox.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  7. #7

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    38
    You've hit the nail on the head. What functions should I use?

  8. #8
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    OK, you've got 2 listboxes: lstBox1 and lstBox2 (for example)

    You'll want to do something like this:

    VB Code:
    1. For i = 0 To lstBox1.ListCount - 1
    2.       if i = 0 then          
    3.       lstBox2.AddItem "0.00"
    4.       else
    5.       lstBox2.AddItem lstBox2.List(i-1) + lstBox1.List(i)
    6.       end if
    7. Next

    And you'll want to put that in the lstBox1_Change event.

    Or something like that... I didn't test that. You get the idea?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  9. #9

    Thread Starter
    Member
    Join Date
    Dec 2003
    Posts
    38
    Thanks for your help, but just one more thing. How do I solve the problem of adding times together (base 60)?

  10. #10
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    umm... what is base 60? Never heard of it.

    The only thing I can say is to convert it, add it together, then convert it back!?
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

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