dcsimg
Results 1 to 10 of 10
  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    10

    [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    I know this is weirdly worded but,

    I have a project that allows you to put a list in a textbox and puts the values in a listbox.

    Is there any way to make the text you put in the textbox change my label from the text going down in order

    Example:

    This is what I use
    Code:
     Dim rnd As New Random
     Dim randomIndex As Integer = rnd.Next(0, ListBox2.Items.Count - 1)
     Label2.Text = (ListBox2.Items(randomIndex))
    I want the Label2 to = the items in the textbox or listbox but not randomly. I wan't it to make the label change to whatever is in the textbox from top to bottom in a row, Not randomized. I need this so that there aren't any repeats.

    And I need a way of checking if all of the items in listbox or textbox are checked so that it can stop changing the label.

    Thx to anyone that can help

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,907

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    That question seems to be designed to be as confusing and uninformative as possible. You really ought to work on providing a FULL and CLEAR explanation of the problem. My guess is that you're saying that you want to display one item from the ListBox in the Label at a time and, perhaps on a Button Click (but who knows), you want to display the next item. If that's the case then you simply need to store the index in a variable. That variable would be initialised to 0 and each time you want to show the next item you simply increment that variable and then display the item at that index. E.g.
    vb.net Code:
    1. Private itemIndex As Integer = 0
    2.  
    3. Private Sub ShowNextItem()
    4.     itemIndex += 1
    5.  
    6.     If itemIndex = ListBox1.Items.Count Then
    7.         'Wrap to first item.
    8.         intemIndex = 0
    9.     End If
    10.  
    11.     Label1.Text = ListBox1.GetItemText(ListBox1.Items(itemIndex))
    12. End Sub
    Last edited by jmcilhinney; Jun 12th, 2018 at 08:53 PM.
    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

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,527

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    I want the Label2 to = the items in the textbox or listbox but not randomly.
    So why you are using Random class?

    For TextBox use Lines property



  4. #4

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    10

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    Thanks jmcilhinney thats what I was trying to do exactly what I wanted to do. Is there any way of checking if the list has ran through once instead of repeating?

    Next time I will try to word it better.

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,907

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    Quote Originally Posted by ExoTiic View Post
    Is there any way of checking if the list has ran through once instead of repeating?
    That's already in the code. What did you think this was doing?
    vb.net Code:
    1. If itemIndex = ListBox1.Items.Count Then
    If you don't want to wrap then don't wrap. I did say that that was just an example. Write your code to do what you want to do.
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    10

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    Oh, I just quickly put it in. Sorry for asking for so much code but is there a way to stop it from starting on the second line. It doesn't start on the first line of the list.

  7. #7
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    98,907

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    As I said, my code was simply an example. If you need different behaviour then change the code accordingly. You need to spend at least a little time to understand what the code actually does rather than just telling us what you want and expecting us to write it for you.
    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

  8. #8

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    10

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    I don't understand it, I'm going to lookup and figure out how it works and what to do to fix any further errors.

  9. #9
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,527

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    Move itemIndex += 1 below Label1.Text = ListBox1.GetItemText(ListBox1.Items(itemIndex))



  10. #10

    Thread Starter
    New Member
    Join Date
    Jun 2018
    Posts
    10

    Re: [Need Fast Help] Making a textbox/listbox's items go in order on requests.

    Yea, I figured this out already. Thanks for the help though!

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.