我有一个mousemove事件处理程序附加到Excel UserForm中名为lstUneditedStudents的3列列表框。绑定列为数字1.该列包含字母数字字符串,如“A202H”。为什么我在此代码中使用Null无效? (ErrorLog是我自己的类,它将错误记录到工作表中。这很顺利,在我调试时记录我的错误。)
Private Sub lstUneditedStudents_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
On Error Resume Next
If Button = 1 Then
Dim dob As DataObject, listValue As String
listValue = lstUneditedStudents.value
If listValue <> "" Then
Set dob = New DataObject
dob.SetText listValue
dob.StartDrag
End If
End If
If Err.Number <> 0 Then
Dim errLog As New ErrorLog
errLog.Log "frmEditClasses", "lstUneditedStudents_MouseMove", Err.Source, Err.Description, Err.Number
End If
End Sub
当您单击列表框时,会出现恼人的延迟,然后在重新填充之前列表框变为空白。一旦你让它稳定下来,拖动工作和其他子程序处理从这个列表框到另一个列表框的移动。但是,仍然会出现此错误。
答案 0 :(得分:1)
我认为你只需要在将它赋给变量之前检查lstUneditedStudents.value是否为null。例如:
Private Sub lstUneditedStudents_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
On Error Resume Next
If Button = 1 Then
Dim dob As DataObject, listValue As String
If Not IsNull(lstUneditedStudents.value) Then
listValue = lstUneditedStudents.value
If listValue <> "" Then
Set dob = New DataObject
dob.SetText listValue
dob.StartDrag
End If
End If
End If
If Err.Number <> 0 Then
Dim errLog As New ErrorLog
errLog.Log "frmEditClasses", "lstUneditedStudents_MouseMove", Err.Source, Err.Description, Err.Number
End If
End Sub