• Hello and welcome to our new forums. We upgraded our forum sites to a more robust and modern system which we hope you will enjoy. Be sure to check out your profile by clicking the button on the top right and configure your preferences, signature, time zone, avatar, etc. as you wish. If you need help with using this new forum'ware try the help link on the bottom right.

    Click here to review your account now.

Recursion?

ideprize

Well-known member
Joined
Oct 19, 2011
Messages
72
Programming Experience
10+
Hi All. Below you see the code to a very simple form which I created to duplicate a strange behavior on a much larger form and I am not sure what to make of it.
VB.NET:
Public Class Form1
    Dim str1 As String

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        MsgBox("form1 loaded")
        Me.Show()
    End Sub

    Private Sub TextBox1_Click(sender As Object, e As EventArgs) Handles TextBox1.Click

    End Sub

    Private Sub TextBox1_Enter(sender As Object, e As EventArgs) Handles TextBox1.Enter
        MsgBox("box1 in")
    End Sub

    Private Sub TextBox1_Leave(sender As Object, e As EventArgs) Handles TextBox1.Leave
        MsgBox("box1 out")
        str1 = TextBox1.Text
        'TextBox2.Select()
        TextBox3.Select()
    End Sub

    Private Sub TextBox2_Click(sender As Object, e As EventArgs) Handles TextBox2.Click

    End Sub

    Private Sub TextBox2_Enter(sender As Object, e As EventArgs) Handles TextBox2.Enter
        MsgBox("box2 in")
        MsgBox("str1 = " + str1)
    End Sub

    Private Sub TextBox2_Leave(sender As Object, e As EventArgs) Handles TextBox2.Leave
        MsgBox("box2 out")
    End Sub

    Private Sub TextBox3_Click(sender As Object, e As EventArgs) Handles TextBox3.Click

    End Sub

    Private Sub TextBox3_Enter(sender As Object, e As EventArgs) Handles TextBox3.Enter
        MsgBox("box3 in")
        MsgBox("str1 = " + str1)
    End Sub

    Private Sub TextBox3_Leave(sender As Object, e As EventArgs) Handles TextBox3.Leave
        MsgBox("box3 out")
    End Sub
End Class
The form itself is the default form in VS 2013. It has 3 labels (vertical) and 3 textboxes next to them. If you use the textbox2.select() command in the textbox1_leave sub the program transfers to the textbox2_enter sub as expected. If you use the textbox3.select() command, however, the the program cycles twice in the textbox1_leave sub prior to leaving and then cycles twice in the textbox3_enter sub. I can only assume that this happens something to do with "tabindex" but what is really disturbing is the code is executed twice in the "from sub" and the "to" sub. This can't be normal. Any thoughts on this would be greatly appreciated. I have attached a jpeg image of the form itself.
Respectfully,
Ideprize
 

Attachments

Last edited by a moderator:

Herman

Well-known member
Joined
Oct 18, 2011
Messages
872
Location
Montreal, QC, CA
Programming Experience
10+
Hi,

Please edit your post and put the code inside a code block, inserted as below:

4442
 

ideprize

Well-known member
Joined
Oct 19, 2011
Messages
72
Programming Experience
10+
Thanks for your response Herman. As it turned out I found a discussion about this same problem on the web. The solution is NOT to use the "leave" handler but the "validated" handler. After placing the transfer select code in the validated handler the transfer happened without incident. You can definitely say I learned something on this one.
 
Top Bottom