By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,619 Members | 2,510 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,619 IT Pros & Developers. It's quick & easy.

Visual Basic Electric Billing program

P: 1
Hello friends. I am Jessie from the Philippines. Friends my problem is how to restrict my textbox so that the users cannot encode a letter.
Sep 28 '07 #1
Share this Question
Share on Google+
5 Replies


Expert 5K+
P: 8,434
Hello friends. I am Jessie from the Philippines. Friends my problem is how to restrict my textbox so that the users cannot encode a letter.
This has been covered in a couple of recent posts here. But probably your simplest solution is to use a Masked Edit control, which allows you to control the format of the input.

Otherwise, you can filter out the keys you don't want by intercepting them in the KeyDown event procedure.
Sep 28 '07 #2

jamesd0142
100+
P: 469
Code may be slightly incorrect but the idea is here...

on form keypress function,

if e.keychar() <> "0" | "1" | "2".......| "9" then
msgbox("please only use digits")
end if
Sep 28 '07 #3

QVeen72
Expert 100+
P: 1,445
Hi,

Write this code in KeyPress Event of textbox :

Expand|Select|Wrap|Line Numbers
  1. Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
  2.     If IsNumeric(e.KeyChar) Then
  3.         e.Handled = False
  4.     Else
  5.         e.Handled = True
  6.     End If
  7. End Sub
  8.  

REgards
Veena
Sep 28 '07 #4

P: 8
Hi ,

i just want to thank you for the piece of code i got from you.
it's working perfectly on VB 2005 controls, however we're building our controls using Microsoft expression-Blend(user interface) and then program the user interface via Vb 2005. Now the problem is that the keypressed event doesn't show when we use the code on our User interface. Do you know any other event we can use for that code.
Oct 6 '07 #5

QVeen72
Expert 100+
P: 1,445
Hi,

You can check in Changed Event of the textbox, it fires whenever you add/edit/delete anything in a textbox, maybe you may have to modify a bit.

Regards
Veena
Oct 6 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.