by P N Bendigeri (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Mon 2nd October 2000
Date Added: Mon 8th February 2021
Rating: (1 Votes)
1. First procedure, for Allowing Only Numeric (0-9) and in between only one Period "." This is useful for the object which has, content of
1. First procedure, for Allowing Only Numeric (0-9) and in between only
one
Period "." This is useful for the object which has, content of single
or
double data types .
2. Second Procedure, for clearing the objects contents e.g. Text Box,
Combo
Box, Option Button. You can update this procedure with other control
objects.
''************************************************************************
*
Option Explicit
Public Sub AllowNumericWithSingleDot(MyAscii As Integer, MyText As
Control)
If MyAscii = 8 Then Exit Sub
If Chr(MyAscii) = "." Then
If MyText.Text <> "" Then
If InStr(1, MyText, ".") <> 0 Then MyAscii = 0
Else
MyAscii = 0
End If
Exit Sub
End If
If (Chr(MyAscii) < "0" Or Chr(MyAscii) > "9") And Chr(MyAscii) <> "."
Then
MyAscii = 0
End If
End Sub
''------------------------ClearAll Procedure -------------------------
Public Sub ClearAll(Optional Frm As Form, _
Optional txtBox As Boolean = True, _
Optional txtCob As Boolean = True, _
Optional txtOpt As Boolean = True)
''-------------------------------------------------------------
Dim MyControl As Control
''-------------------------------------------------
For Each MyControl In Frm.Controls
''---------------------
If txtBox Then
If TypeOf MyControl Is TextBox Then
MyControl.Text = ""
End If
End If
''-----------------------
If txtCob Then
If TypeOf MyControl Is ComboBox Then
MyControl.Text = ""
End If
End If
''-----------------------
If txtOpt Then
If TypeOf MyControl Is OptionButton Then
MyControl.Value = False
End If
End If
''----------------------
Next
''-----------------------------------------
End Sub
''************************************************************************
*
''--------------------Examples using the above procedures --------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
AllowNumericWithSingleDot KeyAscii, Text1
End Sub
Private Sub Text2_KeyPress(KeyAscii As Integer)
AllowNumericWithSingleDot KeyAscii, Text2
End Sub
''---- By default clearing of all the objects contents is True
'' --- See the procedure "ClearAll" ---------
Private Sub Command1_Click()
ClearAll Form1
End Sub
No comments have been posted about 1. First procedure, for Allowing Only Numeric (0-9) and in between only one Period . This is usef. Why not be the first to post a comment about 1. First procedure, for Allowing Only Numeric (0-9) and in between only one Period . This is usef.