Option Explicit
Public SelStart As Long
Public Text18 As String
Private Sub Text18_KeyPress(KeyAscii As Integer)
Dim strParsed() As String
Dim strPostKeyValue As String
If SelStart = 0 Then
strPostKeyValue = Chr(KeyAscii) & Text18
Else
strPostKeyValue = Left$(Text18, SelStart) & Chr(KeyAscii) & Mid$(Text18, SelStart + 1)
End If
strParsed = Split(strPostKeyValue, "x", , vbTextCompare)
If (UBound(strParsed) >= 0) And (UBound(strParsed) < 2) Then
If IsNumeric(strParsed(LBound(strParsed))) And (IsNumeric(strParsed(UBound(strParsed))) Or Len(strParsed(UBound(strParsed))) = 0) Then
Else
KeyAscii = 0
End If
Else
If IsNumeric(Chr(KeyAscii)) Then
Else
KeyAscii = 0
End If
End If
End Sub
Since the default property of a textbox is its Text property, I thought this would be simple enough to replace the variable references with Text18 qualified references. Unfortunately, I missed a couple and could not use the compiler to double-check my syntax.
Option Explicit
Type TextBoxProperties_struc
Text As String
SelStart As Long
SelLength As Long
End Type
Public Text18 As TextBoxProperties_struc
Public Sub Text18_KeyPress(KeyAscii As Integer)
Dim strParsed() As String
Dim strPostKeyValue As String
If Text18.SelStart = 0 Then
strPostKeyValue = Chr(KeyAscii) & Text18.Text
Else
strPostKeyValue = Left$(Text18.Text, Text18.SelStart) & Chr(KeyAscii) & Mid$(Text18.Text, Text18.SelStart + 1)
End If
strParsed = Split(strPostKeyValue, "x", , vbTextCompare)
If (UBound(strParsed) >= 0) And (UBound(strParsed) < 2) Then
If IsNumeric(strParsed(LBound(strParsed))) And (IsNumeric(strParsed(UBound(strParsed))) Or Len(strParsed(UBound(strParsed))) = 0) Then
Else
KeyAscii = 0
End If
Else
If IsNumeric(Chr(KeyAscii)) Then
Else
KeyAscii = 0
End If
End If
End Sub
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (0)