[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 183
  • Last Modified:

I am making an IRC chat program and I need...

I am making an irc chat program and when I get the names of the people in the chat room it puts them in a text box like this:
Carl Gary Mike Jhon
But I need them to be added to a list box! But if there is a space in the name like this:
Jhon Shroom Kitty Catt
It makes kitty and Catt to seperate names how should I go about making this work? If it is even possible? Also if it isn't possible, then how might I go about making it add just the names to the list box? Thanx........
0
Shroom
Asked:
Shroom
  • 3
  • 2
1 Solution
 
idcanadaCommented:

If you have te listbox read a string,
you will not have this problem of spaces.

The listbox will add it as is.

0
 
idcanadaCommented:
If you have te listbox read a string,
you will not have this problem of spaces.

The listbox will add it as is.
0
 
ShroomAuthor Commented:
Do u have the code for this???
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ShroomAuthor Commented:
I have a text box and need to add em to a list box. But I need it to make the names go like this:
The names are already like this:
Gary Mark Shaun
I need it to make a list box like this:
Gary
Mark
Shaun
--------------
Ok but i know how to do this just cut it off at the space but It if the name has a space in it like Kozy Kitten it makes Kozy Kitten 2 speperate names.
Do u have the code to make this work???
0
 
ShroomAuthor Commented:
I am rejecting ur answer cause there isn't enough info... sorry
0
 
prozakCommented:
Well if a space can be included in the persons name then you're screwed. You can't have spaces delimiting the names if a space can be included in the name because there's no way to know if you're looking at two separate names or just one name with a space in it.

Here's some sample code on adding the names to the list box (delimited with a space):

Option Explicit

Private Const strNameDelimiter As String = " "

Private Sub AddNamesToList(strNames As String, lstList As ListBox)
  Dim intPos As Integer
  Dim strParse As String
 
  'Set up the parsing string
  strParse = Trim(strNames)

  'Find the first occurrence of the delimiter
  intPos = InStr(strParse, strNameDelimiter)

  'Loop while there are still delimiters in the string
  Do While intPos <> 0
   
    'Add the name to the list box
    lstList.AddItem RTrim(Left(strParse, intPos - 1))

    'Remove the name from the list
    strParse = LTrim(Right(strParse, Len(strParse) - intPos))

    'Find the next delimiter
    intPos = InStr(strParse, strNameDelimiter)
  Loop
 
  'If there's anything left in the parsing string, add it to the list
  If strParse <> "" Then
    lstList.AddItem strParse
  End If
End Sub

Private Sub Command1_Click()
  List1.Clear
  AddNamesToList Text1.Text, List1
End Sub
 
I just set up a form with a text box that I could type in the list of names and then had a listbox and command button on the form.

I realize there are probably better ways of doing the parsing by saving of the last position and doing a call to Mid but I just went for the quick and dirty method.

If you really want to support names including a space I suggest using a comma or something else to delimit the name. Then you could just change strNameDelimiter = "," and it would work the same way.

Hope this helps...
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now