我觉得帮助有点小害人,直接这样写不是更好?
If e.DataCol.Name = "托运日期" Then
If e.DataRow.IsNull("托运日期") Then
e.DataRow("货单编号") = Nothing
Else
Dim bh As String = Format(e.DataRow("托运日期"),"yyyyMMdd")
If e.DataRow("货单编号").StartsWith(bh) = False
Dim max As String
Dim idx As Integer
max = e.DataTable.Compute("Max(货单编号)","托运日期 = #" & e.DataRow("托运日期") & "# And [_Identify] <> " & e.DataRow("_Identify"))
If max > "" Then
idx = CInt(max.Substring(bh.length,3)) + 1
idx = 1
End If
e.DataRow("货单编号") = bh & "-" & Format(idx,"000")
End If
End If
End If