nata Posted November 12, 2003 Posted November 12, 2003 I have a problem: in a textbox called amount: you may only use numbers, backspace, delete and decimal (decimal sign in the amount) my code is this: Private Sub txtvakbedrag_keypress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtBedrag.KeyPress Static bolDec As Boolean Dim strBedrag As String = txtBedrag.Text If e.KeyChar <> vbBack And e.KeyChar <> "," And e.KeyChar <> "." And e.KeyChar < "0" Or e.KeyChar > "9" Then e.Handled = True Exit Sub End If If Not bolDec And e.KeyChar = "," Or e.KeyChar = "." Then bolDec = True ElseIf bolDec And e.KeyChar = "," Or e.KeyChar = "." Then e.Handled = True Exit Sub End If If txtBedrag.TextLength > 3 Then If strBedrag.Substring(txtBedrag.TextLength - 4, 1).Equals(",") Or strBedrag.Substring(txtBedrag.TextLength - 3, 1).Equals(".") And e.KeyChar <> vbBack Then e.Handled = True End If End If If txtBedrag.TextLength > 0 Then If strBedrag.Substring(txtBedrag.TextLength - 1, 1).Equals(",") Or strBedrag.Substring(txtBedrag.TextLength - 1, 1).Equals(".") And e.KeyChar <> vbBack Then bolDec = False End If End If End Sub What is wrong whith the code? Quote
Leaders Iceplug Posted November 12, 2003 Leaders Posted November 12, 2003 What happens when you press the button? I think you may need to replace vbBack with If Convert.ToByte(e.KeyChar) = 8 or something like that. Also, aren't those other things supposed to be characters? e.KeyChar <> "."c :) Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Leaders Iceplug Posted November 12, 2003 Leaders Posted November 12, 2003 Did you substitute all of your e.KeyChar <> vbBack with Convert.ToByte(e.KeyChar) <> 8 and did it work? Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
techmanbd Posted November 12, 2003 Posted November 12, 2003 This is what I use. It allows you to puyt numbers in the text box and allows the use of teh backspace Private Sub txtNewPSI_Keypress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtNewPSI.KeyPress 'Only allows numbers to be entered into text box If ((Asc(e.KeyChar) > 57) Or (Asc(e.KeyChar) < 48)) Then If (Asc(e.KeyChar) = 8) Then e.Handled = False Else e.Handled = True Beep() End If End If End Sub Quote Live as if you were to die tomorrow. Learn as if you were to live forever. Gandhi
Leaders Iceplug Posted November 12, 2003 Leaders Posted November 12, 2003 It's recommend to avoid using any of the Microsoft.VisualBasic namespace functions, but it's up to you, as it limits things that you can do with your application. :( Quote Iceplug, USN One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.