Alex Piotto
Board Regular
- Joined
- Jul 5, 2016
- Messages
- 82
- Office Version
- 2007
- Platform
- Windows
Well... hi!
I made a little numberpad to avoid users to enter nothing but numbers in a protected textbox,
but more specifically because i was asked to do an IN and OUT for expenses workbook that does not require the keyboard and must be dumb proof. So...
Please do not laugh at me...
EVERYTHING WORKS ANYWAY...
Now, there is some code behind the numberpad. Here it is:
Every button has its own little code.
The buttons gets whatever is in the textbox and append the new number.
I am sure that it can be done in less of ten lines...
Like with a for each loop perhaps? Still trying to get the logic...
FOR EACH COMMANDBUTTON, NUMBERED FROM 0 TO 9, MORE THE "DOT" AND THE "CANCEL" BUTTON,
GET WHAT IS INTO THE TEXTBOX as a variable,
AND PUT IT BACK FOLLOWED BY THE NEW CLICKED NUMBER.
but no loop code yet to show );
I made a little numberpad to avoid users to enter nothing but numbers in a protected textbox,
but more specifically because i was asked to do an IN and OUT for expenses workbook that does not require the keyboard and must be dumb proof. So...
Please do not laugh at me...
EVERYTHING WORKS ANYWAY...
Now, there is some code behind the numberpad. Here it is:
VBA Code:
Private Sub CommandButton1_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY1 As Integer
KEY1 = ActiveSheet.CommandButton1.Caption
ActiveSheet.TextBox1.Value = myVar & KEY1
End Sub
Private Sub CommandButton2_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY2 As Integer
KEY2 = ActiveSheet.CommandButton2.Caption
ActiveSheet.TextBox1.Value = myVar & KEY2
End Sub
Private Sub CommandButton3_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY3 As Integer
KEY3 = ActiveSheet.CommandButton3.Caption
ActiveSheet.TextBox1.Value = myVar & KEY3
End Sub
Private Sub CommandButton4_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY4 As Integer
KEY4 = ActiveSheet.CommandButton4.Caption
ActiveSheet.TextBox1.Value = myVar & KEY4
End Sub
Private Sub CommandButton5_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY5 As Integer
KEY5 = ActiveSheet.CommandButton5.Caption
ActiveSheet.TextBox1.Value = myVar & KEY5
End Sub
Private Sub CommandButton6_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY6 As Integer
KEY6 = ActiveSheet.CommandButton6.Caption
ActiveSheet.TextBox1.Value = myVar & KEY6
End Sub
Private Sub CommandButton7_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY7 As Integer
KEY7 = ActiveSheet.CommandButton7.Caption
ActiveSheet.TextBox1.Value = myVar & KEY7
End Sub
Private Sub CommandButton8_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY8 As Integer
KEY8 = ActiveSheet.CommandButton8.Caption
ActiveSheet.TextBox1.Value = myVar & KEY8
End Sub
Private Sub CommandButton9_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY9 As Integer
KEY9 = ActiveSheet.CommandButton9.Caption
ActiveSheet.TextBox1.Value = myVar & KEY9
End Sub
Private Sub CommandButton0_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEY0 As Integer
KEY0 = ActiveSheet.CommandButton0.Caption
ActiveSheet.TextBox1.Value = myVar & KEY0
End Sub
Private Sub CommandButtonDot_Click()
Dim myVar As String
myVar = ActiveSheet.TextBox1.Value
Dim KEYDOT As String
KEYDOT = ActiveSheet.CommandButtonDot.Caption
ActiveSheet.TextBox1.Value = myVar & KEYDOT
End Sub
Private Sub CommandButtonCancel_Click()
ActiveSheet.TextBox1.Value = ""
End Sub
Every button has its own little code.
The buttons gets whatever is in the textbox and append the new number.
I am sure that it can be done in less of ten lines...
Like with a for each loop perhaps? Still trying to get the logic...
FOR EACH COMMANDBUTTON, NUMBERED FROM 0 TO 9, MORE THE "DOT" AND THE "CANCEL" BUTTON,
GET WHAT IS INTO THE TEXTBOX as a variable,
AND PUT IT BACK FOLLOWED BY THE NEW CLICKED NUMBER.
but no loop code yet to show );