Numeric Keypad Output to Textbox

Unable to display password on a different form

Page 1 of 1

10 Replies - 9215 Views - Last Post: 11 February 2008 - 08:52 PM Rate Topic: -----

#1 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Numeric Keypad Output to Textbox

Post icon  Posted 11 February 2008 - 05:48 PM

Hi I'm having some trouble with my program. I'm working on a login form which is connected to a database. My problem right now is I can't get the password to display in the textbox. I have a login form that displays a combobox for user names and a textbox for the password. This is for a system that will be touchscreen only, no keyboards or mice. I have it set up to bring up a numeric keypad for the password entry. Basically I want the user to select their user name on the login page, touch the textbox to bring up the keypad form. Here is what I have so far for these two forms:

Login Form
Public Class loginFrm
	Friend globalFacultyNameString As String

	Private Sub loginBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginBtn.Click

		If facultyNameComboBox.SelectedIndex <> -1 Then
			globalFacultyNameString = facultyNameComboBox.Items(facultyNameComboBox.SelectedIndex).ToString

			mainFrm.Show()
			Me.Hide()

		Else
			MessageBox.Show("Please select a faculty name")
		End If


	End Sub

	Private Sub loginFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'TODO: This line of code loads data into the 'FacultyDataSet.FacultyPassword' table. You can move, or remove it, as needed.
		Me.FacultyPasswordTableAdapter.Fill(Me.FacultyDataSet.FacultyPassword)
		Me.facultyNameComboBox.SelectedIndex = -1

	End Sub

	Private Sub facultyPinTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles facultyPinTextbox.GotFocus
		keypadFrm.Show()
		keypadFrm.BringToFront()
		Me.Text = keypadFrm.pinString
	End Sub

End Class



Keypad Form
Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
		 
			pinString += selectedBtn.Text

		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		Me.Close()
	End Sub
End Class



Now I'm thinking that the password doesn't show up because keypad form closes right? How would I get it to display in the textbox on the other form? Also this program is actually a grading program so I will need to reuse the keypad to enter scores/percentages later on. How can I reuse it? Do I need to make a class or something?


Any help is greatly appreciated. I'm very new to vb.net.

Attached image(s)

  • Attached Image
  • Attached Image

This post has been edited by skalover89: 11 February 2008 - 05:49 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Numeric Keypad Output to Textbox

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 05:56 PM

What you're going to want to do is to create an instance of the login form in the keypad form, like so


Dim frm As New loginFrm()




Once you have that, you will have access to the controls on that form, so you can do something like this:


Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button

   '>>>>> ADD THIS <<<<<	
	Private frm As New loginFrm()

	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
		   '>>>> USE THE INSTANCE OF THE FORM HERE <<<<
			'Now use the instance of your other form to gain access to
			'your textbox so you can populate it
			frm.YourTextBox.Text += selectedBtn.Text

			pinString += selectedBtn.Text

		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		Me.Close()
	End Sub
End Class




The code I've added as an example is marked with '>>>> <<<<

Hope that helps :)

This post has been edited by PsychoCoder: 11 February 2008 - 05:58 PM

Was This Post Helpful? 0
  • +
  • -

#3 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 06:20 PM

I think I've added what you were saying to my keypad form but now I'm getting an error. Am I misinterpreting your instructions? Thank you for your help!

Error 1 'facultyPinTextbox' is not a member of 'System.Windows.Forms.Form'.

Keypad Form
Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button
	Private loginFrm As New Form()
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			loginFrm.facultyPinTextbox.Text += selectedBtn.Text
			pinString += selectedBtn.Text

		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		Me.Close()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#4 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 06:49 PM

Yes you are misinterpreting, but theres a good chance I didnt explain it well enough so for that I apologize. You need to change this line
Private loginFrm As New Form() to Private frm As New loginFrm(). This will create an instance of your loginFrm, giving you access to its controls.

Now you change this line
loginFrm.facultyPinTextbox.Text += selectedBtn.Text to this
frm.facultyPinTextbox.Text += selectedBtn.Text
Was This Post Helpful? 0
  • +
  • -

#5 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 07:39 PM

View PostPsychoCoder, on 11 Feb, 2008 - 07:49 PM, said:

Yes you are misinterpreting, but theres a good chance I didnt explain it well enough so for that I apologize. You need to change this line
Private loginFrm As New Form() to Private frm As New loginFrm(). This will create an instance of your loginFrm, giving you access to its controls.

Now you change this line
loginFrm.facultyPinTextbox.Text += selectedBtn.Text to this
frm.facultyPinTextbox.Text += selectedBtn.Text


I think I misread your original post and switched where the loginFrm was suppose to go. Temporary dyslexia? Possibly. I fixed the changes you mentioned and the error goes away but I'm still at the same problem. The password doesn't show up in the textbox. Is this because I'm closing the keypad form on the OK button click? Also I'm going to have to reuse the keypad on other forms so should I make a class or something or a function? Do I need to use an array or something as well?

On the loginFrm I've removed Me.Text = keypadFrm.pinString from the facultyPinTextbox_GotFocus subprocedure.

Login Form

Public Class loginFrm
	Friend globalFacultyNameString As String

	Private Sub loginBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginBtn.Click

		If facultyNameComboBox.SelectedIndex <> -1 Then
			globalFacultyNameString = facultyNameComboBox.Items(facultyNameComboBox.SelectedIndex).ToString

			mainFrm.Show()
			Me.Hide()

		Else
			MessageBox.Show("Please select a faculty name")
		End If


	End Sub

	Private Sub loginFrm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
		'TODO: This line of code loads data into the 'FacultyDataSet.FacultyPassword' table. You can move, or remove it, as needed.
		Me.FacultyPasswordTableAdapter.Fill(Me.FacultyDataSet.FacultyPassword)
		Me.facultyNameComboBox.SelectedIndex = -1

	End Sub

	Private Sub facultyPinTextbox_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles facultyPinTextbox.GotFocus
		keypadFrm.Show()
		keypadFrm.BringToFront()

	End Sub

End Class



Keypad Form
Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button
	Private frm As New loginFrm()
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			frm.facultyPinTextbox.Text += selectedBtn.Text
			pinString += selectedBtn.Text

		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		Me.Close()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#6 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 07:44 PM

Inside the following code block make this change to ensure you're actually getting values from your keypad form:


With Me
	 MessageBox.Show(selectedBtn.Text)
	 frm.facultyPinTextbox.Text += selectedBtn.Text
	 pinString += selectedBtn.Text
End With



This will tell you whether you're actually getting values from your keypad. Try that, let me know the results and we can go from there :)
Was This Post Helpful? 0
  • +
  • -

#7 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 08:00 PM

View PostPsychoCoder, on 11 Feb, 2008 - 08:44 PM, said:

Inside the following code block make this change to ensure you're actually getting values from your keypad form:


With Me
	 MessageBox.Show(selectedBtn.Text)
	 frm.facultyPinTextbox.Text += selectedBtn.Text
	 pinString += selectedBtn.Text
End With



This will tell you whether you're actually getting values from your keypad. Try that, let me know the results and we can go from there :)


Yes the messagebox displays the number when I press a button. Actually I previously had a textbox on the keypad form just to verify for myself that it was appending the text correctly in the textbox. Doing it on the actual keypad form worked, but I haven't been able to get it to another form.
Was This Post Helpful? 0
  • +
  • -

#8 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 08:07 PM

Now that we know the keypad is working, try setting the value of the textbox on your login form before you close the keypad form, like this:


Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Private frm As New loginFrm()
	Dim selectedBtn As Button
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			pinString += selectedBtn.Text
		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		'Now set the value of your textbox
		frm.facultyPinTextbox.Text = pinString
		Me.Close()
	End Sub
End Class


Was This Post Helpful? 0
  • +
  • -

#9 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 08:21 PM

View PostPsychoCoder, on 11 Feb, 2008 - 09:07 PM, said:

Now that we know the keypad is working, try setting the value of the textbox on your login form before you close the keypad form, like this:


Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Private frm As New loginFrm()
	Dim selectedBtn As Button
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			pinString += selectedBtn.Text
		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		'Now set the value of your textbox
		frm.facultyPinTextbox.Text = pinString
		Me.Close()
	End Sub
End Class



Nope still doesn't work.
Was This Post Helpful? 0
  • +
  • -

#10 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1632
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 08:45 PM

Its not working because we're creating a new loginFrm, which isnt what we want in VB.Net (sorry was still thinking in C#). Change your code to this:


Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			pinString += selectedBtn.Text
		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		'Now set the value of your textbox
		loginFrm.facultyPinTextbox.Text = pinString
		Me.Close()
	End Sub
End Class



In VB.Net we can access the other form directly, whereas in C# we have to create an instance of the form. Sorry for the confusion.
Was This Post Helpful? 0
  • +
  • -

#11 skalover89  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 13-December 07

Re: Numeric Keypad Output to Textbox

Posted 11 February 2008 - 08:52 PM

View PostPsychoCoder, on 11 Feb, 2008 - 09:45 PM, said:

Its not working because we're creating a new loginFrm, which isnt what we want in VB.Net (sorry was still thinking in C#). Change your code to this:


Public Class keypadFrm

	' Declare module-level variables
	Private selectedColor As Color
	Dim selectedBtn As Button
	Friend pinString As String

	Private Sub keypad1Btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypad1Btn.Click, _
	keypad0Btn.Click, keypad2Btn.Click, keypad3Btn.Click, keypad4Btn.Click, keypad5Btn.Click, keypad6Btn.Click, _
	keypad7Btn.Click, keypad8Btn.Click, keypad9Btn.Click

		selectedBtn = CType(sender, Button)

		With Me
			pinString += selectedBtn.Text
		End With
	End Sub

	Private Sub keypadOkBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keypadOkBtn.Click
		'Now set the value of your textbox
		loginFrm.facultyPinTextbox.Text = pinString
		Me.Close()
	End Sub
End Class



In VB.Net we can access the other form directly, whereas in C# we have to create an instance of the form. Sorry for the confusion.


YES! It worked! Thank you so much. I've been agonizing over this for days. Now how would I make this so that I can reuse the keypad form for other forms? Should I make a global function. I think one of the bigger problems I have with just starting out is that I'm not sure when I should use certain things. For instance, how do you know when to make a class or to use an array?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1