Results 1 to 7 of 7

Thread: ListBox Order Selection

  1. #1

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    ListBox Order Selection

    I have this code:
    Code:
        Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            SendCurrentItem()
            If itemIndex = ListBox1.Items.Count Then
                itemIndex = 0
            End If
        End Sub
    
        Private Sub SendCurrentItem()
            Dim Item = ListBox1.GetItemText(ListBox1.Items(itemIndex))
            SendKeys.Send(Item)
            SendKeys.Send("{Enter}")
            itemIndex += 1
        End Sub
    
        Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 
            Timer1.Start()
        End Sub
    What that code does is it will take all of the items from ListBox1 and it will use SendKeys to type out each of the items every single time the timer ticks from BOTTOM to TOP.

    I was wondering, how would I make it so you can choose in which order you would like the items to be typed out?

    I would like the user to be able to choose if they would like the items to be typed out from BOTTOM to TOP, TOP to BOTTOM, RANDOMLY and ONLY SELECTED ITEM.

    If randomly is chosen I would just like it to send out each item from the ListBox1 at random, no order.
    For example, if I had 1,2,3,4 and 5 as my items it would look like this.

    1
    2
    3
    4
    5

    If random is selected it has the possibility to send the items like this 1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5.
    Last edited by Flavor Flav; May 16th, 2013 at 11:29 AM.

  2. #2
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: ListBox Order Selection

    For top to bottom and reverse you can simply sort the items in ascending or descending order before starting your timer. For selected item don't activate your timer and just call SendCurrentItem() in the listbox selectionchanged event. For random you can use a random number generator and remove each item from the list as it is selected.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  3. #3
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: ListBox Order Selection

    If random is selected it has the possibility to send the items like this 1,1,1,1,1,2,2,2,2,2,3,3,3,3,3,3,4,4,4,4,4,4,5,5,5,5,5.
    This is evidently some new meaning of the word random that I have not previously encountered!
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  4. #4

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: ListBox Order Selection

    Quote Originally Posted by dunfiddlin View Post
    This is evidently some new meaning of the word random that I have not previously encountered!
    I am just saying that I want it to take all of the items and spit them out randomly, not in just a random order, completely random.

    So instead of it going like

    2
    5
    1
    3
    4

    It can go like 1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,5,5,5.

  5. #5
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: ListBox Order Selection

    Quote Originally Posted by Flavor Flav View Post
    I am just saying that I want it to take all of the items and spit them out randomly, not in just a random order, completely random.

    So instead of it going like

    2
    5
    1
    3
    4

    It can go like 1,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,5,5,5.
    In that case the term random does not apply at all.
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

  6. #6

    Thread Starter
    Member
    Join Date
    May 2013
    Posts
    57

    Re: ListBox Order Selection

    Quote Originally Posted by circuits2 View Post
    In that case the term random does not apply at all.
    It CAN do that...

  7. #7
    Frenzied Member circuits2's Avatar
    Join Date
    Sep 2006
    Location
    Kansas City, MO
    Posts
    1,027

    Re: ListBox Order Selection

    Quote Originally Posted by Flavor Flav View Post
    It CAN do that...

    Random is random. Period. Seriously, what point are you trying to make?
    Show the love! Click (rate this post) under my name if I was helpful.

    My CodeBank Submissions: How to create a User Control | Move a form between Multiple Monitors (Screens) | Remove the MDI Client Border | Using Report Viewer with Visual Studio 2012 Express

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