469,572 Members | 1,306 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,572 developers. It's quick & easy.

String Manipulating within List

Hi
I'm very new to VB (using VB6)
I have two lists one blank and one containing names in the format of surname
and then forename.I also have a combo box containing forenames.When I
select a forename from my combo box I need to add the corresponding surname
into the blank list box.What is the best way to do this? hope this make
sense

TIA

--
cheers dude
************
kinŽsole
************

Jul 17 '05 #1
12 5065

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
I'm very new to VB (using VB6)
I have two lists one blank and one containing names in the format of surname
and then forename.I also have a combo box containing forenames.When I
select a forename from my combo box I need to add the corresponding surname
into the blank list box.What is the best way to do this? hope this make
sense

How did you build the lists? The combo and listbox both have an ItemData
property that may be of use when you are adding names. Post a small example
so we can see what you've got so far....

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2
The easiest thing is for me to give you an example.
I have a list box (lstfullnames) a combo box (cmbforenames) and an empty
list box (lstsurnames)

In lstfullnames is the name Smith Bob. In cmbforenames is the name Bob. When
I click on Bob in the combo box in need to see if the name is in the
lstfullnames list and if it is then enter the surname (Smith) into the
lstsurname list box.

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40**********@corp.newsgroups.com...

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
I'm very new to VB (using VB6)
I have two lists one blank and one containing names in the format of surname and then forename.I also have a combo box containing forenames.When I
select a forename from my combo box I need to add the corresponding surname into the blank list box.What is the best way to do this? hope this make
sense

How did you build the lists? The combo and listbox both have an ItemData
property that may be of use when you are adding names. Post a small

example so we can see what you've got so far....

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #3
You're missing the point. You will learn more if you show us what you've
attempted so we can comment and straighten you out in your handling of the
code. Just handing you an answer won't teach you anything. We understand
what you want, now let's see the source you've tried in order to achieve the
result.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:b2******************************@news.teranew s.com...
: The easiest thing is for me to give you an example.
: I have a list box (lstfullnames) a combo box (cmbforenames) and an empty
: list box (lstsurnames)
:
: In lstfullnames is the name Smith Bob. In cmbforenames is the name Bob.
When
: I click on Bob in the combo box in need to see if the name is in the
: lstfullnames list and if it is then enter the surname (Smith) into the
: lstsurname list box.
:
: "Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
: news:40**********@corp.newsgroups.com...
: >
: > "KinŽsole" <ki******@NOSPAMhotmail.com> wrote
: >
: > > I'm very new to VB (using VB6)
: > > I have two lists one blank and one containing names in the format of
: surname
: > > and then forename.I also have a combo box containing forenames.When I
: > > select a forename from my combo box I need to add the corresponding
: surname
: > > into the blank list box.What is the best way to do this? hope this
make
: > > sense
: >
: >
: > How did you build the lists? The combo and listbox both have an
ItemData
: > property that may be of use when you are adding names. Post a small
: example
: > so we can see what you've got so far....
: >
: > LFS
: >
: >
: >
: >
: > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
: > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
: > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
:
:
Jul 17 '05 #4
OK here's my code so far.This works if I have both surname and forename in
the forename combo box.I don't know how to Manipulate the full name in the
list to allow me to match just the first name.
Thanks for any help.
Option Explicit

Private Sub cmbForenames_Click()
Dim namestr, namestr1, namestr2, namestr3, output, value As String
Dim num, number, count As Integer
Dim flag As Boolean

Let number = lstFullNames.ListCount
Let num = cmbForenames.ListIndex
Let namestr = cmbForenames.List(num)

Let namestr = LTrim$(namestr)

Let namestr = RTrim$(namestr)

Let namestr = UCase(Left$(namestr, 1)) + Right$(namestr, Len(namestr) -
1)

For count = 0 To number

If lstFullNames.List(count) = namestr Then
flag = True

End If

Next count
If flag = False Then
MsgBox ("name is not in the list")
Else
Let namestr2 = Len(namestr)
Let namestr1 = InStr(1, namestr, " ")
Let namestr3 = Left$(namestr, namestr1)
lstsurnames.AddItem (namestr3)

End If

End Sub

Private Sub cmdExit_Click()
Unload Me
End Sub

"Randy Birch" <rg************@mvps.org> wrote in message
news:ed*********************@twister01.bloor.is.ne t.cable.rogers.com...
You're missing the point. You will learn more if you show us what you've
attempted so we can comment and straighten you out in your handling of the
code. Just handing you an answer won't teach you anything. We understand
what you want, now let's see the source you've tried in order to achieve the result.

--

Randy Birch
MVP Visual Basic
http://vbnet.mvps.org/
Please respond only to the newsgroups so all can benefit.
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:b2******************************@news.teranew s.com...
: The easiest thing is for me to give you an example.
: I have a list box (lstfullnames) a combo box (cmbforenames) and an empty
: list box (lstsurnames)
:
: In lstfullnames is the name Smith Bob. In cmbforenames is the name Bob.
When
: I click on Bob in the combo box in need to see if the name is in the
: lstfullnames list and if it is then enter the surname (Smith) into the
: lstsurname list box.
:
: "Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
: news:40**********@corp.newsgroups.com...
: >
: > "KinŽsole" <ki******@NOSPAMhotmail.com> wrote
: >
: > > I'm very new to VB (using VB6)
: > > I have two lists one blank and one containing names in the format of
: surname
: > > and then forename.I also have a combo box containing forenames.When I : > > select a forename from my combo box I need to add the corresponding
: surname
: > > into the blank list box.What is the best way to do this? hope this
make
: > > sense
: >
: >
: > How did you build the lists? The combo and listbox both have an
ItemData
: > property that may be of use when you are adding names. Post a small
: example
: > so we can see what you've got so far....
: >
: > LFS
: >
: >
: >
: >
: > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
: > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
: > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
:
:

Jul 17 '05 #5

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
OK here's my code so far.This works if I have both surname and forename in
the forename combo box.I don't know how to Manipulate the full name in the
list to allow me to match just the first name.


I already asked, how are you building the lists? What you posted did not
show any names....

REF:
: "Larry Serflaten" wrote
: >
: > How did you build the lists? The combo and listbox both have an ItemData
: > property that may be of use when you are adding names. Post a small example
: > so we can see what you've got so far....



-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #6
> Dim namestr, namestr1, namestr2, namestr3, output, value As String
Dim num, number, count As Integer
For the above two lines from your posted code, only 'value' is a String and
'count' an Integer... all other variables are declared as Variants. In VB,
you must specify the type of **each** variable individually.

Let number = lstFullNames.ListCount
Let num = cmbForenames.ListIndex
Let namestr = cmbForenames.List(num)
<<<etc>>>


VB does not require the use of the Let keyword to assign values to variables
or arrays. You can save yourself some typing by leaving it out.
Rick - MVP
Jul 17 '05 #7

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
OK here's my code so far.


Just for your future reference:

When you are looking for help with a problem, it often is beneficial
to work up a small demo to reproduce the problem so that others
can copy and paste the code into VB, to see it on their system.

Some questions don't need a code example (Like; Where is the Help file?)
but those that are syntax or logic related often do need a example.
Also, it often happens, that in the process of building a smaller demo
of the problem, that the answer becomes apparent, and the problem is
solved before it is even posted. It is a learning experience to break
some problem down to just the bare necessities, and if you can't solve
it then, you'll have a small demo to post for others to help find the
answer. Thats why I ask for example code, it is far easier for you to
show me the problem, than for me to guess at what you're doing,
and sometimes the answer becomes apparent just by building the demo.

Of course, another reason is because myself and other regular posters
are also on the look out for students trying to get someone to do their
homework! ;-) If the student shows their work, adding a tweek here
or there is generally enough to get through the 'problem'.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #8
As I say I an very new to VB.
The lists are just constructed at design time.
It is my collage homework but I have reached a point where I am stuck.I can
not figure out how to search for part of a string i.e forename within a
list.I know I need to some how remove the surname form the fullname list but
don't know how.
I thing I need to use ' INSTR' to find the space then use RIGHT$ to remove
the surname but I can get this to work for each entry in the list.
I'm only looking for a pointer!

cheers

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
OK here's my code so far.


Just for your future reference:

When you are looking for help with a problem, it often is beneficial
to work up a small demo to reproduce the problem so that others
can copy and paste the code into VB, to see it on their system.

Some questions don't need a code example (Like; Where is the Help file?)
but those that are syntax or logic related often do need a example.
Also, it often happens, that in the process of building a smaller demo
of the problem, that the answer becomes apparent, and the problem is
solved before it is even posted. It is a learning experience to break
some problem down to just the bare necessities, and if you can't solve
it then, you'll have a small demo to post for others to help find the
answer. Thats why I ask for example code, it is far easier for you to
show me the problem, than for me to guess at what you're doing,
and sometimes the answer becomes apparent just by building the demo.

Of course, another reason is because myself and other regular posters
are also on the look out for students trying to get someone to do their
homework! ;-) If the student shows their work, adding a tweek here
or there is generally enough to get through the 'problem'.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #9
sorry that should read " but I can get this to work for each entry in the
list."

cheers
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:0a******************************@news.teranew s.com...
As I say I an very new to VB.
The lists are just constructed at design time.
It is my collage homework but I have reached a point where I am stuck.I can not figure out how to search for part of a string i.e forename within a
list.I know I need to some how remove the surname form the fullname list but don't know how.
I thing I need to use ' INSTR' to find the space then use RIGHT$ to remove
the surname but I can get this to work for each entry in the list.
I'm only looking for a pointer!

cheers

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
OK here's my code so far.


Just for your future reference:

When you are looking for help with a problem, it often is beneficial
to work up a small demo to reproduce the problem so that others
can copy and paste the code into VB, to see it on their system.

Some questions don't need a code example (Like; Where is the Help file?)
but those that are syntax or logic related often do need a example.
Also, it often happens, that in the process of building a smaller demo
of the problem, that the answer becomes apparent, and the problem is
solved before it is even posted. It is a learning experience to break
some problem down to just the bare necessities, and if you can't solve
it then, you'll have a small demo to post for others to help find the
answer. Thats why I ask for example code, it is far easier for you to
show me the problem, than for me to guess at what you're doing,
and sometimes the answer becomes apparent just by building the demo.

Of course, another reason is because myself and other regular posters
are also on the look out for students trying to get someone to do their
homework! ;-) If the student shows their work, adding a tweek here
or there is generally enough to get through the 'problem'.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----


Jul 17 '05 #10
> I have two lists one blank and one containing names in the format of
surname
and then forename.I also have a combo box containing forenames.When I
select a forename from my combo box I need to add the corresponding surname into the blank list box.What is the best way to do this? hope this make
sense
When you said the above in your first post, I assume you mean you want to
get ALL surnames that match the selected forename, not just the first one
you come to.
For count = 0 To number
If lstFullNames.List(count) = namestr Then
flag = True
End If
Next count
If flag = False Then
MsgBox ("name is not in the list")
Else
Let namestr2 = Len(namestr)
Let namestr1 = InStr(1, namestr, " ")
Let namestr3 = Left$(namestr, namestr1)
lstsurnames.AddItem (namestr3)
End If
End Sub
In the above code snippet that you posted earlier, which I took the liberty
to reformat to make it easier to read (something you should think about in
your future coding), you need to add the names to the lstsurnames ListBox
while inside the For-Next loop (you can't see each separate thing you found
after the loop has finished; unless, of course, you store each found item in
an array for later processing). Move the assignment statements in your Else
block of code into the If-Then block inside of your For-Next loop; however,
you need to change what you are actually assigning... use
lstFullNames.List(count) and not namestr, that is what you want to split
apart. Also, the assignment for namestr3 will include a blank space after it
because the position you found the blank at is used as the count argument in
the Left$ statement... you want to use one less than that count value so
that you don't grab the blank character.

Rick - MVP
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:a8******************************@news.teranew s.com... sorry that should read " but I can get this to work for each entry in the
list."

cheers
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:0a******************************@news.teranew s.com...
As I say I an very new to VB.
The lists are just constructed at design time.
It is my collage homework but I have reached a point where I am stuck.I

can
not figure out how to search for part of a string i.e forename within a
list.I know I need to some how remove the surname form the fullname list

but
don't know how.
I thing I need to use ' INSTR' to find the space then use RIGHT$ to remove the surname but I can get this to work for each entry in the list.
I'm only looking for a pointer!

cheers

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...

"KinŽsole" <ki******@NOSPAMhotmail.com> wrote
> OK here's my code so far.

Just for your future reference:

When you are looking for help with a problem, it often is beneficial
to work up a small demo to reproduce the problem so that others
can copy and paste the code into VB, to see it on their system.

Some questions don't need a code example (Like; Where is the Help file?) but those that are syntax or logic related often do need a example.
Also, it often happens, that in the process of building a smaller demo
of the problem, that the answer becomes apparent, and the problem is
solved before it is even posted. It is a learning experience to break
some problem down to just the bare necessities, and if you can't solve
it then, you'll have a small demo to post for others to help find the
answer. Thats why I ask for example code, it is far easier for you to
show me the problem, than for me to guess at what you're doing,
and sometimes the answer becomes apparent just by building the demo.

Of course, another reason is because myself and other regular posters
are also on the look out for students trying to get someone to do their homework! ;-) If the student shows their work, adding a tweek here
or there is generally enough to get through the 'problem'.

LFS


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----



Jul 17 '05 #11
Thanks for your help so far.I seem to be heading in the right direction
now.Heres my code so far

Private Sub cmbForenames_Click()
Dim namestr, namestr1, namestr2, namestr3, output, value, value1, value2 As
String
Dim num, number, count As Integer
Dim flag As Boolean

Let number = lstFullNames.ListCount
Let num = cmbForenames.ListIndex
Let namestr = cmbForenames.List(num)
Let namestr = LTrim$(namestr)
Let namestr = RTrim$(namestr)
Let namestr = UCase(Left$(namestr, 1)) + Right$(namestr, Len(namestr) -
1)

For count = 0 To number
Let value2 = Len(lstFullNames.List(count))
Let value1 = InStr(1, (lstFullNames.List(count)), " ")
Let value = Right$((lstFullNames.List(count)), value2 -
value1)

If value = namestr Then
flag = True
If flag Then
Let lstFullNames.List(count) =
Left$((lstFullNames.List(count)), value1 - 1)
lstsurnames.AddItem (lstFullNames.List(count))
End If
End If

Next count
If flag = False Then
MsgBox ("name is not in the list")
Else
End If

Ignoring all the string and integers Ive set my problem now is when I remove
the surname from ((lstFullNames.List(count)), it remove it from the actual
list .I have tried ((lstFullNames.List(count)) = newstring but without
success.

Sorry if these question seem a bit dumb but I'm not a natural programmer!!!

Thanks for the help so far
cheers
"Rick Rothstein" <ri************@NOSPAMcomcast.net> wrote in message
news:tJ********************@comcast.com...
I have two lists one blank and one containing names in the format of surname
and then forename.I also have a combo box containing forenames.When I
select a forename from my combo box I need to add the corresponding

surname
into the blank list box.What is the best way to do this? hope this make
sense


When you said the above in your first post, I assume you mean you want to
get ALL surnames that match the selected forename, not just the first one
you come to.
For count = 0 To number
If lstFullNames.List(count) = namestr Then
flag = True
End If
Next count
If flag = False Then
MsgBox ("name is not in the list")
Else
Let namestr2 = Len(namestr)
Let namestr1 = InStr(1, namestr, " ")
Let namestr3 = Left$(namestr, namestr1)
lstsurnames.AddItem (namestr3)
End If
End Sub


In the above code snippet that you posted earlier, which I took the

liberty to reformat to make it easier to read (something you should think about in
your future coding), you need to add the names to the lstsurnames ListBox
while inside the For-Next loop (you can't see each separate thing you found after the loop has finished; unless, of course, you store each found item in an array for later processing). Move the assignment statements in your Else block of code into the If-Then block inside of your For-Next loop; however, you need to change what you are actually assigning... use
lstFullNames.List(count) and not namestr, that is what you want to split
apart. Also, the assignment for namestr3 will include a blank space after it because the position you found the blank at is used as the count argument in the Left$ statement... you want to use one less than that count value so
that you don't grab the blank character.

Rick - MVP
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:a8******************************@news.teranew s.com...
sorry that should read " but I can get this to work for each entry in the
list."

cheers
"KinŽsole" <ki******@NOSPAMhotmail.com> wrote in message
news:0a******************************@news.teranew s.com...
As I say I an very new to VB.
The lists are just constructed at design time.
It is my collage homework but I have reached a point where I am stuck.I
can
not figure out how to search for part of a string i.e forename within
a list.I know I need to some how remove the surname form the fullname list but
don't know how.
I thing I need to use ' INSTR' to find the space then use RIGHT$ to

remove the surname but I can get this to work for each entry in the list.
I'm only looking for a pointer!

cheers

"Larry Serflaten" <Ab***@SpamBusters.com> wrote in message
news:40********@corp.newsgroups.com...
>
> "KinŽsole" <ki******@NOSPAMhotmail.com> wrote
> > OK here's my code so far.
>
> Just for your future reference:
>
> When you are looking for help with a problem, it often is beneficial
> to work up a small demo to reproduce the problem so that others
> can copy and paste the code into VB, to see it on their system.
>
> Some questions don't need a code example (Like; Where is the Help file?) > but those that are syntax or logic related often do need a example.
> Also, it often happens, that in the process of building a smaller
demo > of the problem, that the answer becomes apparent, and the problem is
> solved before it is even posted. It is a learning experience to break > some problem down to just the bare necessities, and if you can't solve > it then, you'll have a small demo to post for others to help find the > answer. Thats why I ask for example code, it is far easier for you to > show me the problem, than for me to guess at what you're doing,
> and sometimes the answer becomes apparent just by building the demo.
>
> Of course, another reason is because myself and other regular posters > are also on the look out for students trying to get someone to do

their > homework! ;-) If the student shows their work, adding a tweek here
> or there is generally enough to get through the 'problem'.
>
> LFS
>
>
>
>
>
>
> -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
> http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
> -----== Over 100,000 Newsgroups - 19 Different Servers! =-----



Jul 17 '05 #12

It will now do what I need it to do.I should have tried newstring
=(lstfullnames.list(count))

thanks for all your help.
That's part one of three complete lol
only two more to do.
thanks again

Cheers

Jul 17 '05 #13

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by lamar_air | last post: by
10 posts views Thread by jt | last post: by
2 posts views Thread by shihaoran | last post: by
4 posts views Thread by shapper | last post: by
7 posts views Thread by Donn Ingle | last post: by
6 posts views Thread by Alexnb | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.