Private Sub AdjustControls
' Call from ALL Change Events
Dim blnEnabled As Boolean
Dim StrW as string
strW = Textcalc1.text
blEnabled = Len(strW) > 0 and ISnumeric(strW)
strW = Textcalc2.text
blEnabled = blnEnabled and Len(strW) > 0 and ISnumeric(strW)
strW = Textcalc3.text
blEnabled = blnEnabled and Len(strW) > 0 and ISnumeric(strW)
cmdCalc.enabled = blnEnabled
End Sub
Private Sub Form_Load()
AdjustControls
End Sub
Private txtcal1_Change()
AdjustControls
End Sub
Private txtcal2_Change()
AdjustControls
End Sub
Private txtcal3_Change()
AdjustControls
End Sub
Private txtcalc1_KeyPress(KeyAscii As Integer)
'KeyPress_Decimal KeyAsscii ' Decimal places?
KeyPress_Number KeyAsscii
End Sub
Private txtcalc2_KeyPress(KeyAscii As Integer)
'KeyPress_Decimal KeyAsscii ' Decimal places?
KeyPress_Number KeyAsscii
End Sub
Private txtcalc3_KeyPress(KeyAscii As Integer)
'KeyPress_Decimal KeyAsscii ' Decimal places?
KeyPress_Number KeyAsscii
End Sub
Public Sub KeyPress_Ucase(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
KeyAscii = Asc(UCase$(Chr$(KeyAscii)))
End Sub
Public Sub KeyPress_Number(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub
On Error Resume Next
If Not Chr$(KeyAscii) Like "[0-9]" Then
KeyAscii = 0
End If
On Error GoTo 0
End Sub
Public Sub KeyPress_AlphaNumeric(KeyAscii As Integer)
If KeyAscii = 8 Then Exit Sub ' BackSpace
If Not (Chr$(KeyAscii) Like "[A-Z0-9]") Then KeyAscii = 0
End Sub
Public Sub KeyPress_Decimals(strText As String, KeyAscii As Integer)
Dim strW As String
On Error Resume Next
If KeyAscii = 8 Then Exit Sub ' BackSpace
strW = Chr$(KeyAscii)
If Not (strW Like "[0-9,.]") Then
KeyAscii = 0
Exit Sub
End If
If strW = "." Then
If InStr(1, strText, ".") Then
KeyAscii = 0
Exit Sub
End If
End If
On Error GoTo 0
End Sub