Private Sub t_OffsetX_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) With CreateObject("VBScript.RegExp") .Pattern = "^[-]?[1-9]?[0-9]?$" If Not .Test(t_OffsetX.Value & Chr(KeyAscii)) Then KeyAscii = 0 End WithEnd Sub
Private Sub t_OffsetX_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim ore As Object Set ore = CreateObject("VBScript.RegExp") With CreateObject("VBScript.RegExp") .Pattern = "[-]?\d{0,2}" If .Replace(t_OffsetX.Value & Chr(KeyAscii), "") <> "" Then KeyAscii = 0 End WithEnd Sub
Private Sub TextBox2_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer) If KeyCode = 8 Then KeyCode = 0 End IfEnd Sub
Private Sub t_OffsetX_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) Dim ore As Object Dim s$, ls&, txt$ Set ore = CreateObject("VBScript.RegExp") With CreateObject("VBScript.RegExp") .Pattern = "[-]?\d{0,2}" ls = t_OffsetX.SelStart txt = t_OffsetX.Value If ls = 0 Then s = Chr(KeyAscii) & txt Else s = Mid(txt, 1, ls) & Chr(KeyAscii) & Mid(txt, ls + 1, Len(txt) - 1) End If If .Replace(s, "") <> "" Then KeyAscii = 0 End WithEnd Sub
Private Sub t_OffsetX_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) With CreateObject("VBScript.RegExp") .Pattern = "^(0|-$|-?[1-9]\d{0,2})$" txt = t_OffsetX.Value char_k = Chr(KeyAscii) sel_Text = t_OffsetX.SelText If sel_Text <> Empty Then ' полное или частичное выделение If Not .Test(Replace(txt, sel_Text, char_k)) Then KeyAscii = 0 Else ' выделения нет ls = t_OffsetX.SelStart If Not .Test(Mid(txt, 1, ls) & char_k & Mid(txt, ls + 1, Len(txt))) Then KeyAscii = 0 End If End WithEnd Sub