Hi,
My form is - a listbox which contains 5 items, a textbox and a button.
ListBox - subjectListBox
TextBox - subjectTextBox
When the button is clicked, I want the 5 items in the listbox to be
compared to the text in the textbox (note: items in listbox are single
words - text in textbox can be many words) - and if any of the items in
the textbox match the an item in the list box, I want a message to
appear.
The error message I keep getting is: 'string' does not contain a
definition for 'Contains'
Here is the code I am trying to use within the button:
int counter;
int flag=0;
for (counter = 0; counter < 5; counter++){
if
(subjectTextBox .Text.Contains( subjectListBox. Items[counter].ToString()))
flag=1;
}
if (flag==1)
MessageBox.Show (strMessage);
I have emailed someone else who tested this code - and it worked for
them!
When this happend, I started a new project, and tried it again from
fresh - still not working.
Possibly a problem with my VSC#2003 insallation?
Any help would be greatly appreciated. 5 1340
> I have emailed someone else who tested this code - and it worked for them!
With all due respect... no it didn't. The compiler is telling you the
truth: the String type does not have a method called "Contains". You
probably want this instead:
boolean found=false;
for (counter = 0; counter < 5 && !found; counter++)
{
if
(subjectTextBox .Text.IndexOf(s ubjectListBox.I tems[counter].ToString()) = 0)
found=true;
}
if (found) MessageBox.Show (strMessage);
Sorry, that should have been:
bool found = false;
Sorry, that should have been:
bool found = false;
Bruce Wood wrote: I have emailed someone else who tested this code - and it worked for them!
With all due respect... no it didn't. The compiler is telling you the truth: the String type does not have a method called "Contains". You probably want this instead:
..net 2.0 (Visual Studio 2005) added a String.Contains method. It's
basically a neater way of saying String.IndexOf( ) >= 0.
Ahh. The evils of answering before asking which version the OP is
running. :-)
So, evidently the OP is running 1.1 (as I am) and the other person was
running 2.0.
Thanks, David. I learn something new every day here. :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rufpirat |
last post by:
Hello
I'm in the middle of trying to build an "AD phone book", and this being
my first try at asp.net, I have a few questions that I hope some of you
might be able to help with:
1. Is it correct, that PageSize equals the max size of the result
set?
2. Is there a way to make asp cache the search result, so the domain
controller won't be...
|
by: Hexman |
last post by:
Hello All,
I'd like your comments on the code below. The sub does exactly what I want it to do but I don't feel that it is solid as all. It seems like I'm
using some VB6 code, .Net2003 code, and .Net2005 code. I'm developing in vb.net 2005.
This test sub just reads an input text file, writing out records to another text file, eliminating...
|
by: pmarisole |
last post by:
This is the first page......
<select size="1" name="Q1_<%=i%>" onChange="calc(<%=i%>)">
<option selected value="<% =rsScores("Q1")
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
|
by: Tanzen |
last post by:
I'm working in visual studio 2005 trying to learn visual basic. Having
come from an VB for Access background, I'm finding it a big learning
curve. I have been working through several e-books which have shown
how to use custom collections to store lists of data. I've coded the
custom collection and before I add members to it, I want to use the...
|
by: hcaptech |
last post by:
This is my Test.can you help me ?
1.Which of the following statement about C# varialble is incorrect ?
A.A variable is a computer memory location identified by a unique name
B.A variable's name is used to access and read the value stored in it
C.A variable is allocated or deallocated in memory during runtime
D.A variable can be initialized...
| |
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...
|
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. ...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
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...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |