virtual keypad login problem

rusty

Member
Joined
May 10, 2010
Messages
9
Programming Experience
Beginner
I'm writing a login screen in vb.net that uses a virtual keypad to enter numbers into two textboxes. I'm trying to allow the user to click on a textbox then click on the number buttons to enter them in that field. Whenever I click the 2nd textbox it writes it in the 1st textbox. What steps do I write in order to have the user freely click between the two fields and then be able to click each button and have it fill the correct field? Do I have to store the text boxes after each time a number is added or changed? The way I'm currently doing it is not correct so I want to start over and get some hints at where to start writing. Thanks...
 
I get the feeling that the code you're using to put the numbers into the text boxes specifies that the number should be added to the first textbox rather than the last textbox that gotfocus. If you can supply the code then it would be possible to verify this.

I have attached a quick piece of code which explains how I would go about dealing with this.

Hopefully this will help you :)
 

Attachments

  • WindowsApplication1.zip
    14.6 KB · Views: 29
Last edited by a moderator:
Am I able to open and run this zip using 2008 express? Should I go ahead and upgrade to 2010, if I'm currently just using vb.net to freshen up my skills? Haven't programmed since 2005, so I'm trying to get back into the swing of things. Also here is my code..

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
TextBox1.Text = TextBox1.Text + "1"
End Sub

I know this is wrong. I'm probably using the focus method wrong. Do I have to test to see if there is a focus to a certain textbox and then write to that textbox?
 
Yeah you should be able open it with 2008 express, I created it with Visual Studio 2008, so should work fine.

The code that is contained in project follows, its not quite as well presented as it would be in the IDE, but hopefully you can still get the idea of the code.

VB.NET:
Public Class Form1
    Private currentTextBox As TextBox

    Private Sub TextBox1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.GotFocus
        currentTextBox = sender
    End Sub
    Private Sub TextBox2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.GotFocus
        currentTextBox = sender
    End Sub

#Region "Number buttons"
    Private Sub btnNum0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum0.Click
        currentTextBox.Text &= "0"
    End Sub
    Private Sub btnNum1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum1.Click
        currentTextBox.Text &= "1"
    End Sub
    Private Sub btnNum2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum2.Click
        currentTextBox.Text &= "2"
    End Sub
    Private Sub btnNum3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum3.Click
        currentTextBox.Text &= "3"
    End Sub
    Private Sub btnNum4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum4.Click
        currentTextBox.Text &= "4"
    End Sub
    Private Sub btnNum5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum5.Click
        currentTextBox.Text &= "5"
    End Sub
    Private Sub btnNum6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum6.Click
        currentTextBox.Text &= "6"
    End Sub
    Private Sub btnNum7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum7.Click
        currentTextBox.Text &= "7"
    End Sub
    Private Sub btnNum8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum8.Click
        currentTextBox.Text &= "8"
    End Sub
    Private Sub btnNum9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNum9.Click
        currentTextBox.Text &= "9"
    End Sub
#End Region

End Class
 
Good to go, and thanks for the help. Went out and got an up to date visual basic book so I can catch back up on some things. I think I should be able to get through everything else as long as my database skills aren't as rusty as my programming skills... We'll see. Thanks again.
 
Back
Top