Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • Leaders
Posted

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

:)

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

  • Leaders
Posted

Did you substitute all of your

e.KeyChar <> vbBack

with

Convert.ToByte(e.KeyChar) <> 8

and did it work?

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Posted

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

Live as if you were to die tomorrow. Learn as if you were to live forever.
Gandhi
  • Leaders
Posted
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. :(

Iceplug, USN

One of my coworkers thinks that I believe that drawing bullets is the most efficient way of drawing bullets. Whatever!!! :-(

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...