Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Decimal Control
Author:
Muhammad Imran Vohra
E-mail:
Click to e-mail author
Website:
http://www.geocities.com/adnysam
Submitted:
3/13/2005
Version:
VB6
Compatibility:
VB6
Category:
Controls
Views:
10132
This code is very usefull for the programers who actually control decimal on Textbox... Example Text1_keypress(keyascii as integer) keyascii = deccontrol(keyascii, text1, 2)
Declarations:
'none
Code:
Public Function DecControl(KeyAscii As Integer, Text As TextBox, ByVal NOOFDEC As Integer) As Integer If KeyAscii = 8 Then DecControl = KeyAscii Exit Function End If If NOOFDEC = 0 Then If InStr(1, "0123456789-", Chr(KeyAscii)) = 0 Then DecControl = 0 Exit Function Else DecControl = KeyAscii Exit Function End If Else If InStr(1, "0123456789.-", Chr(KeyAscii)) = 0 Then DecControl = 0 Exit Function End If End If If Len(Text) - Text.SelStart > NOOFDEC And Chr(KeyAscii) = "." Then DecControl = 0 Exit Function End If If KeyAscii <> 8 Then If InStr(1, Text, ".") <> 0 And Chr(KeyAscii) = "." Then DecControl = 0 Exit Function End If Dim pos As Integer Dim RET As Integer pos = InStr(1, Text.Text, ".") If pos = 0 Then If InStr(1, "0123456789.-", Chr(KeyAscii)) = 0 Then RET = 0 Else RET = KeyAscii End If Else 'IF AFTER DECIMAL If Text.SelStart + 1 > pos Then a = Len(Text.Text) - InStr(1, Text, ".") If a >= NOOFDEC Then RET = 0 Else RET = KeyAscii End If Else RET = KeyAscii End If End If Else RET = KeyAscii End If DecControl = RET End Function
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement