Connecting Tech Pros Worldwide Forums | Help | Site Map

VB.NET: backspace button code?

Newbie
 
Join Date: Oct 2006
Posts: 4
#1: Oct 26 '06
hello.

i have written a calculator program in VB.net as im still new and working things out i have a tiny problem. i have 10 buttons zero to nine, a decimal button, plus button, equals button, textbox display, reset button and a backspace button.

ive done everything except the backspace button. (say if i click a wrong number, i want to go back and click a different 1) but i have no idea what the code is and how i do it.

thanks, help apprechiated :)

Needs Regular Fix
 
Join Date: Oct 2006
Location: Netherlands
Posts: 269
#2: Oct 26 '06

re: VB.NET: backspace button code?


Quote:

Originally Posted by korndevil666

hello.

i have written a calculator program in VB.net as im still new and working things out i have a tiny problem. i have 10 buttons zero to nine, a decimal button, plus button, equals button, textbox display, reset button and a backspace button.

ive done everything except the backspace button. (say if i click a wrong number, i want to go back and click a different 1) but i have no idea what the code is and how i do it.

thanks, help apprechiated :)

hi

backspace is same as Chr(8)
Newbie
 
Join Date: Oct 2006
Posts: 4
#3: Oct 26 '06

re: VB.NET: backspace button code?


Quote:

Originally Posted by albertw

hi

backspace is same as Chr(8)


okay thanks. but what is the code for the button?, havent used chr before
Needs Regular Fix
 
Join Date: Oct 2006
Location: Netherlands
Posts: 269
#4: Oct 26 '06

re: VB.NET: backspace button code?


Quote:

Originally Posted by korndevil666

okay thanks. but what is the code for the button?, havent used chr before

hi
you can use the _keydown method

Expand|Select|Wrap|Line Numbers
  1. Private Sub AnObject_KeyDown(KeyCode As Integer, Shift As Integer)
  2. If KeyCode = vbKeyBack Then
  3. .. enter your code here ...
  4. End If 
  5. End Sub
  6.  
or the _keypress method

Expand|Select|Wrap|Line Numbers
  1. Private Sub AnObject_KeyPress(KeyAscii As Integer)
  2. If KeyAscii = 8 Then
  3. .. enter your code here ...
  4. End If
  5. End Sub
  6.  
Newbie
 
Join Date: Oct 2006
Posts: 4
#5: Oct 26 '06

re: VB.NET: backspace button code?


Quote:

Originally Posted by albertw

hi
you can use the _keydown method

Expand|Select|Wrap|Line Numbers
  1. Private Sub AnObject_KeyDown(KeyCode As Integer, Shift As Integer)
  2. If KeyCode = vbKeyBack Then
  3. .. enter your code here ...
  4. End If 
  5. End Sub
  6.  
or the _keypress method

Expand|Select|Wrap|Line Numbers
  1. Private Sub AnObject_KeyPress(KeyAscii As Integer)
  2. If KeyAscii = 8 Then
  3. .. enter your code here ...
  4. End If
  5. End Sub
  6.  

ohh, yeah it works, thats alot for your help :)
Newbie
 
Join Date: Aug 2006
Posts: 2
#6: Jan 3 '07

re: VB.NET: backspace button code?


Hi .. all..
i am working on login page in maa project using vb.net.
in that after enterring the username if i press the enter i need that control should pass to the submit buton ..can any one give me the code plz
thanks in advance
tq
Newbie
 
Join Date: Aug 2007
Posts: 2
#7: Aug 15 '07

re: VB.NET: backspace button code?


Private Sub txtUser_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 122 Then
txtUser.Text = ""
MsgBox "Enter only alphabets", vbOKOnly
KeyAscii = 8
ElseIf KeyAscii = 58 Or KeyAscii = 63 Or KeyAscii = 59 Or KeyAscii = 60 Or KeyAscii = 61 Or KeyAscii = 62 Then
txtUser.Text = ""
MsgBox "Enter only alphabets", vbOKOnly
KeyAscii = 8
End If
i want 2 make my backspace key work normally wat code should i modify or any better way 2 proceed
Newbie
 
Join Date: Aug 2007
Posts: 2
#8: Aug 15 '07

re: VB.NET: backspace button code?


can u reply the inner code 4 this 2
Private Sub AnObject_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Then
.. enter your code here ...
End If
End Sub
Newbie
 
Join Date: Jul 2009
Posts: 1
#9: Jul 10 '09

re: VB.NET: backspace button code?


Quote:

Originally Posted by korndevil666 View Post

ohh, yeah it works, thats alot for your help :)

hi i am reading your problem ........
you can make one button in the code view and change name=bbackspace then its text property backspace.in property window.....now clicked backspace button
AND USE FOLLOWING CODE
Private Sub bbackspace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bbackspace.Click
Dim d As New Integer

If (TextBox1.Text.Length > 0) Then
d = TextBox1.Text.Length
TextBox1.Text = TextBox1.Text.Remove(d - 1, 1)




End If





End Sub
Reply


Similar .NET Framework bytes