473,770 Members | 5,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
12 5242
> 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.Li st(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.Add Item (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.Li st(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******@NOSPA Mhotmail.com> wrote in message
news:a8******** *************** *******@news.te ranews.com... sorry that should read " but I can get this to work for each entry in the
list."

cheers
"KinŽsole" <ki******@NOSPA Mhotmail.com> wrote in message
news:0a******** *************** *******@news.te ranews.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***@SpamBust ers.com> wrote in message
news:40******** @corp.newsgroup s.com...

"KinŽsole" <ki******@NOSPA Mhotmail.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_Cl ick()
Dim namestr, namestr1, namestr2, namestr3, output, value, value1, value2 As
String
Dim num, number, count As Integer
Dim flag As Boolean

Let number = lstFullNames.Li stCount
Let num = cmbForenames.Li stIndex
Let namestr = cmbForenames.Li st(num)
Let namestr = LTrim$(namestr)
Let namestr = RTrim$(namestr)
Let namestr = UCase(Left$(nam estr, 1)) + Right$(namestr, Len(namestr) -
1)

For count = 0 To number
Let value2 = Len(lstFullName s.List(count))
Let value1 = InStr(1, (lstFullNames.L ist(count)), " ")
Let value = Right$((lstFull Names.List(coun t)), value2 -
value1)

If value = namestr Then
flag = True
If flag Then
Let lstFullNames.Li st(count) =
Left$((lstFullN ames.List(count )), value1 - 1)
lstsurnames.Add Item (lstFullNames.L ist(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******** ************@co mcast.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.Li st(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.Add Item (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.Li st(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******@NOSPA Mhotmail.com> wrote in message
news:a8******** *************** *******@news.te ranews.com...
sorry that should read " but I can get this to work for each entry in the
list."

cheers
"KinŽsole" <ki******@NOSPA Mhotmail.com> wrote in message
news:0a******** *************** *******@news.te ranews.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***@SpamBust ers.com> wrote in message
news:40******** @corp.newsgroup s.com...
>
> "KinŽsole" <ki******@NOSPA Mhotmail.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7939
by: lamar_air | last post by:
I need a piece of code that takes a string like this string1 = "aaa/bbb/ccc/dd" and extracts a string containting the character after the last "/" So for this example the result would be "dd" like this: for i=0; string1.right(i) != '/'; i++ result = string1.mid(i, string1.length())
10
2385
by: jt | last post by:
I'm needing to take a binary string start at a certain position and return a pointer from that postion to the end of the binary stirng. something like this: char bstr; char *pos; pos=mid(bstr,35); / *return a pointer of the rest of the binary string starting at element 35 */
23
9521
by: comp.lang.tcl | last post by:
I have a TCL proc that needs to convert what might be a list into a string to read consider this: ]; # OUTPUTS Hello World which is fine for PHP ]; # OUTPUT {{-Hello}} World, which PHP will print literally as {{-Hello}} World, instead of
2
4213
by: shihaoran | last post by:
I really need help with one my program; it is about arraylist; I do not get it. Can someone please help me with it? Here's the instruction: 1. Your instructor will provide you with a text file, (numbers.txt), containing a large (N <= 1000) number of integers. The integers range in value from 0 to 100. The text file has been created with one value on each line. Due to the potential for the sum of the numbers to be very large, you...
4
13206
by: shapper | last post by:
Hello, How can I transform a Generic List(Of String) to a string as follows: "value1,value2,value3,value4, ..." Thanks, Miguel
9
2682
by: | last post by:
I am interested in scanning web pages for content of interest, and then auto-classifying that content. I have tables of metadata that I can use for the classification, e.g. : "John P. Jones" "Jane T. Smith" "Fred Barzowsky" "Department of Oncology" "Office of Student Affairs" "Lewis Hall" etc. etc. etc. I am wondering what the efficient way to do this in code might be. The dumb and brute-force way would be to loop through the content...
7
2378
by: Donn Ingle | last post by:
Hi, I really hope someone can help me -- I'm stuck. I have written three versions of code over a week and still can't get past this problem, it's blocking my path to getting other code written. This might be a little hairy, but I'll try to keep it short. Situation: I want to pass a string to a function which will parse it and generate objects in a list.
4
1626
by: Wilbert Berendsen | last post by:
Hi, is it possible to manipulate class attributes from within a decorator while the class is being defined? I want to register methods with some additional values in a class attribute. But I can't get a decorator to change a class attribute while the class is still being defined. Something like: class Parser(object): regexps =
6
2504
by: Alexnb | last post by:
Uhm, "string" and "non-string" are just that, words within the string. Here shall I dumb it down for you? string = "yes text1 yes text2 yes text3 no text4 yes text5+more Text yes text6 no text7 yes text8" It doesn't matter what is in the string, I want to be able to know exactly how many "yes"'s there are. I also want to know what is after each, regardless of length. So, I want to
0
9592
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9871
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8887
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5452
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.