David Svedarsky
asked on
How to enter textbox value if another textbox has value
I need sample code that will enter a specific textbox value if another textbox has a specific value.
Both textboxes are databound.
Example:
If textbox1 has a value of "11/02/2007" (or any other random date), textbox2 will have a value of "Finish".
Both textboxes are databound.
Example:
If textbox1 has a value of "11/02/2007" (or any other random date), textbox2 will have a value of "Finish".
You can skip the test for empty string, Textbox1.Text will always return string
IF TextBox1.text = "11/02/2007" then Textbox2.text = "Finish"
IF TextBox1.text = "11/02/2007" then Textbox2.text = "Finish"
The best events to hook it is possibly Textbox1.Validate or Exit (or even Change if you need to update as soon as they hit the last "7")
Dim date1 as DateTime
Dim date1OK as bool
date1 = new DateTime(1,1,1)
try
{
date1 = Convert.ToDateTime(Date1.Text);
Textbox2.text = "Finish"
}
catch
{
date1OK = false;
}
>>You can skip the test for empty string, Textbox1.Text will always return string
true, but its considered best practice to perform all checks. plus once you get used to it it becomes sort of "instinctual"...
true, but its considered best practice to perform all checks. plus once you get used to it it becomes sort of "instinctual"...
Um... it's a bit overkill isn't it.
String.IsEmpty(TextBox.Tex t) === (True)
It's like adding
If TRUE then
IF TRUE then
IF TRUE then
do something....
kinda moot point?
String.IsEmpty(TextBox.Tex
It's like adding
If TRUE then
IF TRUE then
IF TRUE then
do something....
kinda moot point?
maybe so, but i like to think about it like algebra in high school: everybody thinks its useless, you'll never use it. maybe so, but it helps create the necessary neuronal connections for logical thinking (and later in life you one uses those skills in programming .net for example).
furthermore i would tend to think that checking for String.IsEmpty beforehand saves some computing power in doing the comparison IF TextBox1.text = "11/02/2007", which is pointless to run unless the textbox has something in it. i believe that the method IsEmpty is more efficient than the method to extract the Text property of the control when that text exists. i cant back that up, maybe somebody can comment on this?
furthermore i would tend to think that checking for String.IsEmpty beforehand saves some computing power in doing the comparison IF TextBox1.text = "11/02/2007", which is pointless to run unless the textbox has something in it. i believe that the method IsEmpty is more efficient than the method to extract the Text property of the control when that text exists. i cant back that up, maybe somebody can comment on this?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
imitchie, having googled a little bit i found some interesting factoids... apparently, the question about efficiency of checking for emptyness is addressed in this article:
http://www.tbiro.com/Check-empty-string-performance.htm
the conclusions from that one and others, apparently, is:
1) checking for String.Length() is faster than checking for String.IsEmpty()
2) checking for String.Length() is faster when length is shorter
meaning that a more efficient code would look maybe like this:
If String.Length > 0 Then
If TextBox1.Text = "11/02/2007" Then
Textbox2.Text = "Finish"
End If
End If
What is your opinion on this?
http://www.tbiro.com/Check-empty-string-performance.htm
the conclusions from that one and others, apparently, is:
1) checking for String.Length() is faster than checking for String.IsEmpty()
2) checking for String.Length() is faster when length is shorter
meaning that a more efficient code would look maybe like this:
If String.Length > 0 Then
If TextBox1.Text = "11/02/2007" Then
Textbox2.Text = "Finish"
End If
End If
What is your opinion on this?
ASKER
vadim63,
Excellent snippet - very versatile.
I did test all the code samples but vadim63's was the only one that worked for me.
Thanks for all the responses.
Dave
Excellent snippet - very versatile.
I did test all the code samples but vadim63's was the only one that worked for me.
Thanks for all the responses.
Dave
Good luck!
If not string.isempty(TextBox1.Te
if TextBox1.text = "11/02/2007" then
Textbox2.text = "Finish"
end if
end if