Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27514

VS 2010 [RESOLVED] Text box selection based on a sender

$
0
0
Okay this is hard to explain in words (makes it even harder to search for an answer online) but I will try to explain it below is the code I currently have:

Code:

 
Private Sub ClearFocus(ByVal strText As String)
        'This sub checks to see what text box needs to be selected
        'and cleared if an error occurs
        If strText Is "Seasons" Then
            txtSeasons.Clear()
            txtSeasons.Focus()
        ElseIf strText Is "Rookie Age" Then
            txtRookieAge.Clear()
            txtRookieAge.Focus()
        ElseIf strText = "First Name" Then
            txtFirstName.Focus()
        ElseIf strText = "Last Name" Then
            txtLastName.Focus()
        End If
    End Sub

What I would like to know if I could have something like this:

Code:

 
Private Sub ClearFocus(ByVal strText As String)
        'This sub checks to see what text box needs to be selected
        'and cleared if an error occurs
            txt(strText).Clear()
            txt(strText).Focus()
End Sub

The idea is that it would select whatever textbox based on what string was sent to it to strText, so instead of having four if statement clauses I would just have one that would handle them all. So if strText = Goals then it would run txtGoals.Clear() and then txtGoals.Focus(), if it was strText = Assists it would instead run txtAssists.Clear() and txtAssists.Focus() . Thank you in advance for your help, just though I would like to learn a way to shorten the code.

Viewing all articles
Browse latest Browse all 27514

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>