|
-
Feb 16th, 2009, 12:33 PM
#1
Thread Starter
Fanatic Member
[Resolved]Building string from listbox
Does this code look correct to complete the task?
Code:
'store all medications information as string value
While lstMeds.Items.Count > -1
For i = 0 To lstMeds.Items.Count - 1
strActiveMeds = strActiveMeds & lstMeds.SelectedItem & ", "
Next
End While
Thanks.
Last edited by hipopony66; Feb 16th, 2009 at 05:46 PM.
-
Feb 16th, 2009, 12:40 PM
#2
Re: Building string from listbox
First off, the while-loop will never reach an end because you arent removing items from the ListBox, thus not changing the lstMeds.Items.Count property.
And even if you did, the Count property could never go lower than 0 so it'll always be greater than -1.
You are also appending the same item to the string in each iteration in the for-loop; the selected item. You'd need to do something like this:
Code:
For i = 0 To lstMeds.Items.Count - 1
strActiveMeds = strActiveMeds & Cstr(lstMeds.Items(i))
Next
However its always a good idea to use a StringBuilder when building strings like this. Search for "StringBuilder" on MSDN and you'll find out how.
-
Feb 16th, 2009, 12:43 PM
#3
Re: Building string from listbox
-
Feb 16th, 2009, 05:45 PM
#4
Thread Starter
Fanatic Member
Re: Building string from listbox
Thanks. I didn't know anything about the StringBuilder class!
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
|