Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Out of range error when hit Return 1

Status
Not open for further replies.

Ragnarox

Programmer
Oct 2, 2003
141
US
Hello all,

I am getting the following error:

Specified value out of range of acceptable values[/color red]

I get this after i have cleared all the forms within my project. When i am filling out the form a second time the textbox where i am getting this error has the following code :

Code:
Private Sub txtDIPlan_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDIPlan.KeyDown
        If e.KeyCode.ToString = "Enter" Then
            btnAdd.PerformClick()
        End If
    End Sub

The problem is though that when i hit Enter this code does not even get run. The error is in my parent form which is an mdiContainer for all the other forms. But i can hit the enter key on any of the other forms without a problem.



Any help, as always, is greatly appreciated.

Brian
 
I beleive e.KeyCode.ToString is going to return "13" as opposed to e.keycode which will return 13.

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Rick,

I will try that, but why then on the first time through does this code work correctly? That is what i am not getting.

Also when i am going through this the second time this code does not even get hit. When i press then enter key i get the error on the following line

Code:
Public Class frmParent

Any help, as always, is greatly appreciated.

Brian
 
Interesting. I'm not sure, it sounds like the exception is being thrown from another thread. When another thread throws and exception and ends, it will stick the cursor at the head of the class that invoked the thread (I think).

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Could you post more code.

The error is probably being raised in the btnAdd Click event or a method being called by the btnAdd Click event
 
jubble

Here is the code for the btnAdd_Click

Code:
Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        clbDIPlans.Items.Add(txtDIPlan.Text)
        txtDIPlan.Text = ""
        txtDIPlan.Focus()
    End Sub

I am not sure what else would be needed.

The program is running on my machine only because i am still testing it so i am not sure about additional threads but i will look into the Rick.



Any help, as always, is greatly appreciated.

Brian
 
That looks OK. Even if the textbox is empty it shouldn't be generating that error when populating the list (I'm assuming that clbDIPlans is a checked list box)

Are you using third party controls? This would fit in with Rick's idea of different threads.

Could you post the code that clears the form and any other code that might be linked to the problem. I'm wondering if you're destroying the handles when clearing the forms, which would explain why the event isn't firing.

Just as a note it's much easier to use the code

Code:
If e.KeyCode = Keys.Enter Then

rather than a string as then you don't have to worry about case sensitivity or spelling errors
 
jubble,

Thanks for the easier code, i will definetly be putting that in.

As for third party controls, I am not using any. The only additional controls that are in VB are the ones i have created but they are not used in this program.

Here is the code for the clearing of the forms:

Code:
Public Sub ClearAll()
        Dim cntrl As Control

        For Each cntrl In Controls
            If TypeOf cntrl Is TextBox Then
                cntrl.Text = ""
            End If

            If TypeOf cntrl Is ComboBox Then
                cntrl.Text = ""
            End If

            If TypeOf cntrl Is GroupBox Then
                Dim cntrl2 As Control

                For Each cntrl2 In cntrl.Controls
                    If TypeOf cntrl2 Is TextBox Then
                        cntrl2.Text = ""
                    End If

                    If TypeOf cntrl2 Is ComboBox Then
                        cntrl2.Text = ""
                    End If
                Next
            End If
        Next

        Label15.Text = "Disability Plan - Plan Rules"

        prevpos = -1

        clbDIPlans.Items.Clear()
    End Sub

This style of code is used for each form within this project.

I do have one idea, since this is the only control that is causing this to happen, would deleting it and adding a new control with a different name make a difference? I think though that i have done this before, but i have been fighting this error for so long i do not remember if i have or not.

Any help, as always, is greatly appreciated.

Brian
 
Just another idea...are you sure there are no events being fired when you add items to the list or clear the list?

Do a 'Find' on clbDIPlans do see if you left any events or other code lying around...they might be referencing an item index that doesn't exist.

 
Just to make absolutely sure, if you go to the GUI builder, click on the form and look in the properties window for "AcceptButton" it is set to "(none)" correct?

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Whoa...the posts are getting stuck in some sort of time warp. I'll try again...

(Rick's put a new post in also)

Just another idea...are you sure there are no events being fired when you add items to the list or clear the list?

Do a 'Find' on clbDIPlans do see if you left any events or other code lying around...they might be referencing an item index that doesn't exist.

 
Rick,

I do have an Add button on the form, but it is not the default, the default is the textbox. When you hit the enter key, it does a btnAdd.PerformClick to add what was added into the checklist box. The code for the click event is in my third posting in this thread.

Any help, as always, is greatly appreciated.

Brian
 
Rick,

The Accept button is set to none.

Jubble,

I am not using multithreading and it is a checklist box.

In regards to the stepping through the code, i have tried to place a break on the first line in the offending code but it never gets hit after a clear has been done. Do i need to put a break point on all subs and functions after a clear in order to see what is going on, or just on that page?

Any help, as always, is greatly appreciated.

Brian
 
Again, that looks OK.

You could try deleting the control and adding one with a new name but I don't think it will help - it does seem though to be one of those odd errors that have no explanation . Just after you delete it do a 'Find' for the control name to see if anything is left over( particularly in the Form Designer Generated Code )

Try stepping through the code or wrap all the methods in try catch blocks so that you can pin down exactly the method and line of code that is causing the problem.

Are you using multithreading?

Is clbDIPlans a Checked List Box?


 
Damnit Jubble! Stop having your posts repeat! :p

Another side guess here:
Code:
Private Sub txtDIPlan_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDIPlan.KeyDown
  If e.KeyCode.ToString = "Enter" Then
    btnAdd.PerformClick()
    e.Handled() = True
  End If
End Sub

-Rick

----------------------

[monkey] I believe in killer coding ninja monkeys.[monkey]
[banghead]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top