Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a VB Expert!

Join 244,257 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,299 people online right now. Registration is fast and FREE... Join Now!




Linking a selction of text boxes to 1 private sub?

 
Reply to this topicStart new topic

Linking a selction of text boxes to 1 private sub?

DempZ
2 Dec, 2008 - 11:02 AM
Post #1

New D.I.C Head
*

Joined: 2 Dec, 2008
Posts: 11


My Contributions
Hi there,

Pretty new to VB, only started it a few weeks ago so i apologize if this is pretty straight forward.

Basically i have 7 text boxes, and i only want numerics to be entered, no letters at all.

I have the code sorted, but must i do it for each individual text box or can i use some sort of code so that the other 6 text boxes will copy the 1st one i done?

CODE


Private Sub txtDM_KeyPress(KeyAscii As Integer) 'txtDM is the first of my tesx boxes
Select Case KeyAscii
Case 48 To 57, 8 ' 0-9 and backspace
'Let these key codes pass through
Case Else
'All others get trapped
KeyAscii = 0 ' set ascii 0 to trap others input
End Select
End Sub



If its any use, txtCM is my second textbox incase someone can show a way to link smile.gif

Thanks

This post has been edited by DempZ: 2 Dec, 2008 - 11:12 AM

User is offlineProfile CardPM
+Quote Post


jens
RE: Linking A Selction Of Text Boxes To 1 Private Sub?
2 Dec, 2008 - 02:07 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 May, 2008
Posts: 263



Thanked: 18 times
Dream Kudos: 475
My Contributions
I think somthing along these lines should work (haven't tested the code)

vb

Private Sub txtDM_KeyPress(KeyAscii As Integer)
KeyAscii = CheckKeyValid(KeyAscii)
End Sub

Private Sub CheckKeyValid(KeyA As Integer) AS Integer
Select Case KeyA
Case 48 To 57, 8 ' 0-9 and backspace
'Let these key codes pass through
Case Else
'All others get trapped
KeyA = 0 ' set ascii 0 to trap others input
End Select
CheckKeyValid = KeyA
End Sub


/Jens

This post has been edited by jens: 2 Dec, 2008 - 02:11 PM
User is offlineProfile CardPM
+Quote Post

thava
RE: Linking A Selction Of Text Boxes To 1 Private Sub?
2 Dec, 2008 - 03:05 PM
Post #3

D.I.C Addict
Group Icon

Joined: 17 Apr, 2007
Posts: 670



Thanked: 35 times
Dream Kudos: 75
My Contributions
follow this link

http://www.dreamincode.net/code/snippet2630.htm

it's in vb.net
just use the concept only
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 11:06AM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month