Solved

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

Posted on 1998-12-18
6
154 Views
Last Modified: 2010-05-03
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
Comment
Question by:Shroom
  • 3
  • 2
6 Comments
 
LVL 4

Expert Comment

by:idcanada
ID: 1451441

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

The listbox will add it as is.

0
 
LVL 4

Expert Comment

by:idcanada
ID: 1451442
If you have te listbox read a string,
you will not have this problem of spaces.

The listbox will add it as is.
0
 

Author Comment

by:Shroom
ID: 1451443
Do u have the code for this???
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

Author Comment

by:Shroom
ID: 1451444
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
 

Author Comment

by:Shroom
ID: 1451445
I am rejecting ur answer cause there isn't enough info... sorry
0
 
LVL 1

Accepted Solution

by:
prozak earned 0 total points
ID: 1451446
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now