Solved

How to enter textbox value if another textbox has value

Posted on 2007-12-03
11
595 Views
Last Modified: 2008-02-01
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".
0
Comment
Question by:dave_sky
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 13

Expert Comment

by:newyuppie
ID: 20400884
If coding in .NET2, maybe you should be thinking about doing it in the Form Load() event, something like

If not string.isempty(TextBox1.Text) then
  if TextBox1.text = "11/02/2007" then
       Textbox2.text = "Finish"
  end if
end if
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20400898
You can skip the test for empty string, Textbox1.Text will always return string

IF TextBox1.text = "11/02/2007" then Textbox2.text = "Finish"
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20400906
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")
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 20400923

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;
			}

Open in new window

0
 
LVL 13

Expert Comment

by:newyuppie
ID: 20400924
>>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"...
0
 
LVL 25

Expert Comment

by:imitchie
ID: 20400945
Um... it's a bit overkill isn't it.

String.IsEmpty(TextBox.Text)   ===   (True)

It's like adding

If TRUE then
  IF TRUE then
     IF TRUE then
        do something....

kinda moot point?
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 20400984
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?
0
 
LVL 10

Accepted Solution

by:
vadim63 earned 500 total points
ID: 20401055
If IsDate(TextBox1.Text) Then TextBox2.Text = "Finish"
0
 
LVL 13

Expert Comment

by:newyuppie
ID: 20402528
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?
0
 

Author Comment

by:dave_sky
ID: 20404713
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
0
 
LVL 10

Expert Comment

by:vadim63
ID: 20404803
Good luck!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SLMGR Switches Are Not Working On KMS Host 3 88
I need help making a collection from a class in VB.Net 3 32
VB.NET 1 21
RLDC Reporting in Visual studio 11 13
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now