| | |
how to use the keypress function is visual basic 6
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2007
Posts: 23
Reputation:
Solved Threads: 0
hey need some help guys. for example i have a text box and i will have input in it. but only numeric ones are allowed to be inputted in the text box if a character for example "a" is pressed the text box will not change and type the "a" and if a numeric button for example is 1, the text box will have 1. how can i do this? thanks.
try this following code :
' This code for string input or other (comma,drop,question mark etc) except numeric
' This code for numeric input only, other input cannot be written
' This code for string input only (drop, comma, question mark cannot be written)
actually you can combine this with ascii code. look the code in ascii table and you can let what input can be written.
OK.hope this helps..
' This code for string input or other (comma,drop,question mark etc) except numeric
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Text1_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then Text1.Locked = False Else Text1.Locked = True End If End Sub
' This code for numeric input only, other input cannot be written
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Text2_KeyPress(KeyAscii As Integer) If KeyAscii < 48 Or KeyAscii > 57 Then Text2.Locked = True Else Text2.Locked = False End If End Sub
' This code for string input only (drop, comma, question mark cannot be written)
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Private Sub Text3_KeyPress(KeyAscii As Integer) If KeyAscii > 65 Or KeyAscii > 97 Then Text1.Locked = False Else Text1.Locked = True End If End Sub
actually you can combine this with ascii code. look the code in ascii table and you can let what input can be written.
OK.hope this helps..
Last edited by Jx_Man; Jan 5th, 2008 at 8:02 am. Reason: code tags
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Apr 2007
Posts: 106
Reputation:
Solved Threads: 16
You don't have to lock the text box, just set KeyAscii to 0. Also, you need to handle the backspace key to allow users to fix errors:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
'Let these key codes pass through
Case Else
'All others get trapped
KeyAscii = 0
End Select
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 48 To 57, 8
'Let these key codes pass through
Case Else
'All others get trapped
KeyAscii = 0
End Select
End Sub
thx SCBWV...
nice recovery for my post...
nice recovery for my post...
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- Visual Basic (Visual Basic 4 / 5 / 6)
- Visual Basic coding for excel database - am tearing my hair out! (Visual Basic 4 / 5 / 6)
- variable argument list in Visual Basic (Visual Basic 4 / 5 / 6)
- idea in ivrs using visual basic and oracle (Visual Basic 4 / 5 / 6)
- Visual Basic and C++ and Debug and DLLs (Visual Basic 4 / 5 / 6)
- The Move.....Visual Basic 6, Visual Basic .NET ? (VB.NET)
- Visual Basic.net (VB.NET)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: how to print directly
- Next Thread: Apply code to 'x' button on form
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






