Changing contents the TextBoxes simultanously

gripusa

Well-known member
Joined
Apr 29, 2005
Messages
73
Location
Lahore Pakistan
Programming Experience
1-3
Hi! i have seven text boxes which shows the in time for each day of the week , now when i want to provide the user to facility that if he changes the time of any one of them , a pop up message opne p and asks should he want to apply the same time in all the other days, if yes then i have iterate over each textbox (i have stored theri references in an array) and update the Text property to reflect the new change
it works quite well but then it breaks and terminate with an exception , "Object is not set to instance " like this
so whats wrong with it, as when i debugged it works quite ok but as soon as i finish iterating and came out of loop it raises the exception
 
You could do the following but replace the ctl.Text = "" with the time that you are using.

For
Each ctl As Control In Controls
If TypeOf ctl Is TextBox Then

ctl.Text = ""

End If

Next

Cleako
 
gripusa post the itteration sub that you're using as well as the array that you're using as well

perhaps kulrom, jmcihiny (i can never remember what his sn is) or i could help you fix the loop that's causing the exception
 
This is slightly off-topic, but I'd suggest using DateTimePickers to enter time data. Everyone (you are by no means the only one) seems determined to use TextBoxes for everything when there are more appropriate controls available.
 
ha ha ha yeah you are right , but some time you have to see some context specific problem and i m in one of them as well, otherwise i do understand there is DateTimePciker Control and one thing i m from VC as well and we have them on our tool box in VC6 as well.
 
I suggest that you follow JB's advice then. It sounds like the problem is not with the TextBoxes but something outside that loop. Are you saying that it works while debugging but not in release, or while debugging it gets through the loop and then throws an exception? If its during debugging, you simply have to press the break button on the exception dialogue and test your variables. If it happens on a call to one of your methods, it may be that the exception is actually thrown further up the call stack. If you do this:
VB.NET:
		Try

		Catch ex As Exception
			Debug.WriteLine(ex.ToString())
		End Try
you'll get the call stack at the time of the exception in your Output window, so you know exactly what line the exception was thrown on. You then put a breakpoint on that line and test all variables next run.
 
Back
Top