Guest lbsaltzman Posted November 26, 2002 Posted November 26, 2002 Here is a problem I ran into in vb .net in relation to some validation called from a value changed event. On a Windows form I have a NumericUpDown control and a Date time Picker control. The Date time picker is used to select the beginning date of an agreement and the NumericUpDown control to set the number of days the control is in force. I have code to recalculate the end date based on the values of these to fields. I want to call that code from value_changed and leave events of these two controls. The code works with the leave event and crashes badly with the value_changed event. The code also works with a variety of keypress and mouse events as well. Here is the code for the problem. I left out the Try, Catch end try in this sample, but wheither that is present or not I am getting a stackoverflow error message and the error triggers when the form is loading. As I said this same validation works perfectly placed in almost any event. Private Sub dtpStartDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dtpStartDate.ValueChanged Call ChangeAgrmntEndDate() End Sub Private Sub ChangeAgrmntEndDate() Dim DateReturn As Date Dim StartDate As Date Dim dblAgrmntLngth As Double Dim strDateReturn As String StartDate = Me.dtpStartDate.Value dblAgrmntLngth = Me.updAgrmntLngth.Value DateReturn = CalculateAgrmntDate(StartDate, dblAgrmntLngth) strDateReturn = CStr(DateReturn) Me.txtEndDate.Text = strDateReturn End Sub If anyone has had any experience yet with the vagaries errors during events that can explain this I will greatly appreciate some help. Quote
*Gurus* divil Posted November 26, 2002 *Gurus* Posted November 26, 2002 Your code is run when something in the textbox changes, and the code changes the contents of the textbox. If you think about it, your code is going to recurse on itself until it runs out of stack space. The usual way to fix this is with a variable that you can temporarily set to mark the code not to execute, when you change the contents programmatically. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.