Solved

Getting info from a string in a listbox

Posted on 1998-10-09
3
131 Views
Last Modified: 2010-04-30
Say there are multiple strings of information in a list box with a person's first name then last name then phone number in that order, and there is a button next to the list box that should only get the selected person's first name from the string and stores it in a global variable. How do you code the button so this occurs?
0
Comment
Question by:Gardiun
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Accepted Solution

by:
waty earned 50 total points
ID: 1439061
you should separate each item with a character :

ex :
 cbCombo.Add sFirstName & ";" & sLastName & ";" & sPhone

or

 cbCombo.Add sFirstName & vbTab & sLastName & vbTab & sPhone


in the command button, do as follow :

 sLine = cbCombo.List(cbCombo.ListIndex)
 nPos = Instr(sLine , ";") ' or nPos = Instr(sLine , vbTab)
 sFirsName = Left(sLine , 1, nPos-1)

0
 

Author Comment

by:Gardiun
ID: 1439062
It has a problem with this line:
sFirsName = Left(sLine , 1, nPos-1)

The message read "wrong number of arguments or invalid property assignment." What did you declare nPos as?
0
 
LVL 14

Expert Comment

by:waty
ID: 1439063
Dim sFirsName as String
dim sLine as String
dim nPos  as long
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

756 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