Private Sub txtBarCode_Change()
Dim i As Integer
    If Len(Trim(Me.txtBarCode.text)) = 9 Then
        Me.Cell1.SetCurSheet (0)
        If Me.Cell1.GetRows(0) > 4 Then
            For i = 0 To Me.Cell1.GetRows(0)
                If Trim(Me.Cell1.GetCellString(1, i + 4, 0)) = Trim(Me.txtBarCode.text) Then
                    Me.Cell1.SetCellDouble 2, i + 4, 0, 1
                    Cell1.SetCellTextColor 1, 4 + i, 0, Cell1.FindColorIndex(RGB(255, 0, 0), 1)
                    
                    ' Else
                      ' MsgBox ("没有输入的票号!")
                End If
            Next
        End If
        Me.txtBarCode.text = ""
        Me.txtBarCode.SetFocus
    
    End If
End Sub
我想在Trim(Me.Cell1.GetCellString(1, i + 4, 0)) <>Trim(Me.txtBarCode.text)的情况下,MsgBox ("没有输入的票号!")这个消息框,可是我加进去,出现几行记录就有几个消息框,怎么处理啊,我只想要一个就是需要写一个小算法,记录比较情况吧,可我不知道怎么写

解决方案 »

  1.   

    LZ试一下吧:
    Private Sub txtBarCode_Change() 
        Dim i As Integer, iTest%    If Len(Trim(Me.txtBarCode.text)) = 9 Then 
            Me.Cell1.SetCurSheet (0) 
            If Me.Cell1.GetRows(0) > 4 Then 
                iTest = 0
                For i = 0 To Me.Cell1.GetRows(0) 
                    If Trim(Me.Cell1.GetCellString(1, i + 4, 0)) = Trim(Me.txtBarCode.text) Then 
                        Me.Cell1.SetCellDouble 2, i + 4, 0, 1 
                        Cell1.SetCellTextColor 1, 4 + i, 0, Cell1.FindColorIndex(RGB(255, 0, 0), 1) 
                        iTest = 1: Exit For
                    End If 
                Next 
                if (iTest = 0) then MsgBox "没有输入的票号!", 48, "票号错误"
            End If
            Me.txtBarCode.text = ""
            Me.txtBarCode.SetFocus
        End If 
    End Sub
      

  2.   

    你把MSGBOX放在循环里面,当然就循环一次出现一次啦