Results 1 to 10 of 10

Thread: Help for beginner needed!

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7

    Help for beginner needed!

    Hi All. I'm having trouble with some code and I'm sure I'm making it harder than it has to be. I'm trying to display all of the items contained in a combo box in a Message Box but I can't seem to get it to work properly. Any ideas on how to get it going? Here's the code I've been fiddling with but no matter what I try, I can only get one item to display in the message box.

    VB Code:
    1. 'Handles the click event for the Yacht Types button under the File Menu.
    2.  
    3.         Dim intIndex As Integer = 0
    4.         Dim YachtTypes As String
    5.  
    6.         For intIndex = 0 To intIndex = cboYachtType.Items.Count - 1
    7.             YachtTypes = CStr(cboYachtType.Items(intIndex))
    8.         Next
    9.  
    10.         MessageBox.Show("Yacht Type Summary" & ControlChars.CrLf _
    11.         & "Brian Reid" & ControlChars.CrLf & ControlChars.CrLf _
    12.         & "Yacht Types: " & YachtTypes, "Yacht Summary", _
    13.         MessageBoxButtons.OK, MessageBoxIcon.Information)
    Thanks for the help! Brian

  2. #2
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    try

    Code:
     Dim intIndex As Integer = 0
            Dim YachtTypes As String
    
            For intIndex = 0 To intIndex = cboYachtType.Items.Count - 1
                YachtTypes &= CStr(cboYachtType.Items(intIndex))
            Next
    
            MessageBox.Show("Yacht Type Summary" & ControlChars.CrLf _
            & "Brian Reid" & ControlChars.CrLf & ControlChars.CrLf _
            & "Yacht Types: " & YachtTypes, "Yacht Summary", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7
    Thanks for the help. I just tried it, but to no avail. It still lists only the first item. I don't know if it matters or not, but I'm using .Net 2003.

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7
    To make it easier, I've saved the entire VB project folder as a zip so anyone who wants to try and help me can download it. Here's the link:

    http://webpages.charter.net/brianreid/public/Yachts.zip

    Thank you!

  5. #5
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    i dont know why your having problem with the code posted above, but anyway try thisway out

    Code:
            Dim enm As IEnumerator = cboYachtType.Items.GetEnumerator()
            Dim YachtTypes As String
            While enm.MoveNext
                YachtTypes &= enm.Current
            End While
            MsgBox("Yacht Type Summary" & vbCrLf & "Brian Reid" & vbCrLf & vbCrLf & "Yacht Types: " & yachttypes)

    sorry i dont have vs2003 , cant see the your posted project

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7
    LOL, I don't know why it's not working either. The code you just posted did work. My Professor will be surprised that I've coded with code we've never learned.

    Hate to bug you again, but is it possible to separate each of the items in the message box with a comma, a line feed, etc. using the code you just posted? It kind of just jumbles it all together.

    Once again, Thank You.

  7. #7
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    this puts a comma between each item ( it removes the last comma since theres no item after it , after the loop )



    Code:
    Dim enm As IEnumerator = cboYachtType.Items.GetEnumerator()
    
    
            Dim YachtTypes As String
            While enm.MoveNext
                YachtTypes &= enm.Current & ","
            End While
            YachtTypes = YachtTypes.Substring(0, YachtTypes.Length - 1)
            MsgBox("Yacht Type Summary" & vbCrLf & "Brian Reid" & vbCrLf & vbCrLf & "Yacht Types: " & YachtTypes)

  8. #8
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    problem solved with your code too ( i hope )

    the mistake were in the red parts

    Code:
    Dim intIndex As Integer = 0
            Dim YachtTypes As String
    
            For intIndex = 0 to cboYachtType.Items.Count - 1 
                YachtTypes &= CStr(cboYachtType.Items(intIndex))
            Next
    
            MessageBox.Show("Yacht Type Summary" & ControlChars.CrLf _
            & "Brian Reid" & ControlChars.CrLf & ControlChars.CrLf _
            & "Yacht Types: " & YachtTypes, "Yacht Summary", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

  9. #9
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    so what you finally want is >>

    Code:
    Dim intIndex As Integer = 0
            Dim YachtTypes As String
    
            For intIndex = 0 to cboYachtType.Items.Count - 1 
                YachtTypes &= CStr(cboYachtType.Items(intIndex)) & " ,"
            Next
            YachtTypes = YachtTypes.Substring(0, YachtTypes.Length - 1)
    
    
            MessageBox.Show("Yacht Type Summary" & ControlChars.CrLf _
            & "Brian Reid" & ControlChars.CrLf & ControlChars.CrLf _
            & "Yacht Types: " & YachtTypes, "Yacht Summary", _
            MessageBoxButtons.OK, MessageBoxIcon.Information)

  10. #10

    Thread Starter
    New Member
    Join Date
    Oct 2003
    Posts
    7
    Wow, you have no idea how much I appreciate that. A few silly mistakes makes a big difference.

    You're awesome! Thanks

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