|
-
Nov 17th, 2003, 01:35 AM
#1
Thread Starter
New Member
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:
'Handles the click event for the Yacht Types button under the File Menu.
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)
Thanks for the help! Brian
-
Nov 17th, 2003, 03:22 AM
#2
Addicted Member
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)
-
Nov 17th, 2003, 03:39 AM
#3
Thread Starter
New Member
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.
-
Nov 17th, 2003, 03:43 AM
#4
Thread Starter
New Member
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!
-
Nov 17th, 2003, 03:49 AM
#5
Addicted Member
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
-
Nov 17th, 2003, 04:05 AM
#6
Thread Starter
New Member
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.
-
Nov 17th, 2003, 04:13 AM
#7
Addicted Member
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)
-
Nov 17th, 2003, 04:18 AM
#8
Addicted Member
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)
-
Nov 17th, 2003, 04:21 AM
#9
Addicted Member
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)
-
Nov 17th, 2003, 04:24 AM
#10
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|