|
Here are two general points:
1. Create one database installed on server
2. Develop application / chat form which you will get last inserted message from users
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.aktualiteti.com
|
|
|
|
|
public Boolean valid()
{
for (int i=0; i < cmbSampleName.Items.Count; i++)
{
if (txtSampleName.Text == cmbSampleName.Items[i].ToString())
{
return true;
break;
}
else
{
return false;
}
}
}
i want to check weather the current text in textbox is present in combobox or not
plz help
|
|
|
|
|
Your code makes no sense, you're only checking the first item.
Also, you're not returning anything if there are no items in the combobox, which is why you have a compile error.
Maybe this is what you wanted? (warning: untested!)
public bool IsValid()
{
for (int i = 0; i < cmbSampleName.Items.Count; i++)
{
if (txtSampleName.Text == cmbSampleName.Items[i].ToString())
return true;
}
return false;
}
|
|
|
|
|
I suggest stepping through it with the debugger and paying attention to what it does.
If you cannot do that, then trace through the code manually setting i to 0 and considering both cases where if is true and where it is false. Then ask what happens if i is 1 - can it get there?.
Here's a clue - it will not reach the break line.
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
He won't be able to step through it as the code won't compile.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
That's why I suggested a manual trace - but do people get taught how to that these days?
Regards
David R
---------------------------------------------------------------
"Every program eventually becomes rococo, and then rubble." - Alan Perlis
The only valid measurement of code quality: WTFs/minute.
|
|
|
|
|
riced wrote: but do people get taught how to that these days?
Well the course I did tried to. Of course they went to the other extreme and got us to design the application fully on paper and then set up test and run through manually and document the results, only once we had proved that the design worked as expected could we actually program it. I suppose it's good practice for simple programs (which was the case), to grasp the concept. But for most things it's usually quicker to design a more rough idea of what should be happening, code it and then debug the little problems.
So in short, yes people do get taught that these days.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
|
|
|
|
|
SK Genius wrote: it's usually quicker to design a more rough idea of what should be happening, code it and then debug the little problems
Isn't this the essence of Test Driven Development?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
You may thing that you've got them all covered, but there's a big condition that you haven't checked. What happens if cmbSampleName.Items.Count is 0? The for loop won't execute, so a code path is causing you a problem. What you could do, is rewrite this by removing return false and place it outside the scope of the for loop (i.e. before the final }).
This turns your method into:
public bool Valid()
{
for (int i=0; i < cmbSampleName.Items.Count; i++)
{
if (txtSampleName.Text == cmbSampleName.Items[i].ToString())
return true;
}
return false;
} Alternatively, you could use the Find method on cmbSampleName.Items to find out if the name is present or not (if it returns null, it's not present).
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Just to add the above:
Member 4081808 wrote: return true;
break;
Won't compile either: unreachable code - the "break" will never be executed as the method returns before it.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
lol thats wrong -> compile would succeed..
but bring up a warining as you described
xyz
|
|
|
|
|
You mean you don't have "treat all warnings as errors" enabled?
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
|
No. I develop in WPF where warnings are deferred until runtime.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Have you tried adding
<option strict="on">
?
|
|
|
|
|
This aint Java
|
|
|
|
|
hmm i use #develop with C# xD
|
|
|
|
|
I have been thinking about how it would make sense to write code like this.
After all, you wouldn't have written it like this if you had no reason to do so.
I think I figured it out - did you think that return value; only sets the value that will be returned, instead of immediately* returning that value? It all makes sense then - as long as they are not equal, you would keep the return value on false ; and when they are equal you'd set the return value to true and exit the method.
The problem with that is, of course, that return doesn't "set the value that will be returned", it immediately* exits the method (and it also returns the specified value, of course)
*: except in the presence of try /finally
|
|
|
|
|
After the for loop
you should return a value,
because perhaps the for loop is not executed
|
|
|
|
|
Hi All
I am using TcpClient to read from a socket and I set the property ReceiveTimeout to a value let's say 3 seconds.
As per documentation, after the read fails because of a Timeout, an IOexception is thrown.
After that point, each time I call ReadLine the exception is systematically thrown again and again.
What to do to reset the Timeout value or to renable the reading from a socket with no worry?
I reset a new value for ReceiveTimeout but it doesn't work.
Do you know what to do?
|
|
|
|
|
Don't know if this will help you or not.....
I have a UDP client based application. We were having troubles reconnecting the computers when one of the network cards would go down for some reason. What I ended up doing was checking for exceptions, and depending on the exceptions, I would then try closing/reopening the socket.
Maybe this is what you need to do.
You should also probably test for the case I had which was to have the apps communicating, and then disable the network adapter and reenable it.
|
|
|
|
|
i don't think the exception is thrown because of the ReceiveTimeout.. if nothings availible to read the buffer would be empty and that would may by throw an exception..
try to check before reading using the property
<br />
if (client.DataAvailable > 0)<br />
{<br />
...<br />
string line = client.ReadLine();<br />
...<br />
}<br />
|
|
|
|
|
hi Freakyit
thank you very much for this snippet..I didn't know about it
Mmstn
|
|
|
|
|
A timeout closes the connection. You have to re-establish the connection. Make sure your TcpClient has keepalive set to true, and make sure the server isn't timing out on you. Also, a higher timeout value can help unless there is a major issue with the server timing out, in which case you will just wait longer for the exception.
|
|
|
|
|
Thank you very mcuh! I didn't know that! It helps!
mnstn
|
|
|
|