|
我也来看看,窗体部分控件代码如下
- Private Sub CommandButton2_Click()
- Dim i, j As Integer, sH As Worksheet
- Dim rngNo As Range
- Dim r As Long
- If Me.TextBox1 = "" Then
- MsgBox "请扫码", , "提示"
- ElseIf Len(TextBox1.Text) > 55 Then
- MsgBox "条码超过55个字符,请重新扫描!"
- ElseIf Me.TextBox3 = "" Or Me.TextBox4 = "" Or Me.TextBox5 = "" Then
- MsgBox "条码不符合规范"
- Else
- Set sH = Sheets("数据库")
- Set rngNo = sH.Columns(2).Find(UserForm1.TextBox1.Value)
- If Not rngNo Is Nothing Then
- r = rngNo.Row
- Else
- r = sH.Range("a" & Rows.Count).End(xlUp).Row + 1
- If r < 3 Then r = 3
- End If
- With sH
- .Range("a" & r).Value = r - 2
- .Range("b" & r).Value = TextBox1.Text
- .Range("g" & r).NumberFormatLocal = "yyyy-mm-dd": .Range("g" & r).Value = Date
- .Range("h" & r).NumberFormatLocal = "hh:mm:ss": .Range("h" & r).Value = Time
- .Range("I" & r).Value = Val(TextBox2.Text)
- .Cells(r, "D") = Me.TextBox3
- .Cells(r, "E") = Me.TextBox4
- .Cells(r, "F") = Me.TextBox5
- End With
- ThisWorkbook.Save
- Application.EnableEvents = False
- For i = 1 To 5
- Me.Controls("TextBox" & i) = ""
- Next i
- Application.EnableEvents = True
- TextBox1.SetFocus
- End If
- End Sub
- Private Sub TextBox1_Change()
- Me.TextBox2 = Len(Me.TextBox1)
- If Me.TextBox1 = "" Then
- For i = 3 To 5
- Me.Controls("TextBox" & i) = ""
- Next
- End If
- End Sub
- Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- Dim tmpStr$, reGxp As Object, tmPobj As Object
- Set reGxp = CreateObject("vbScript.regExp")
- reGxp.Global = True
- reGxp.Pattern = ".{7}(\d+)\D+(\d+)1T\d+(\D+\d{4})"
- If KeyCode = 13 Then
- KeyCode = 0
- tmpStr = Me.TextBox1 & ""
- If reGxp.test(tmpStr) Then
- Set tmPobj = reGxp.Execute(tmpStr)
- Me.TextBox3 = tmPobj(0).submatches(0)
- Me.TextBox4 = tmPobj(0).submatches(1)
- Me.TextBox5 = tmPobj(0).submatches(2)
- End If
- End If
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|