rs.Open "select * from Wirerack where 文件号='" & Trim(Text1(0).text) & "' order by 排号,架号,层号,道号", cnn, adOpenKeyset, adLockOptimistic
If rs.RecordCount > 0 Then
If rs.RecordCount = 1 Then '一条记录直接读
rs.MoveFirst
a = rs.Fields("排号")
b = rs.Fields("架号")
c = rs.Fields("层号")
d = rs.Fields("道号")
Text1(5).text = a & b & c & d
End If
If rs.RecordCount = 2 Then '两条记录直接比
rs.MoveFirst
a = rs.Fields("排号")
b = rs.Fields("架号")
c = rs.Fields("层号")
d = rs.Fields("道号")
Text1(5).text = a & b & c & d
rs.MoveNext
a1 = rs.Fields("排号")
b1 = rs.Fields("架号")
c1 = rs.Fields("层号")
d1 = rs.Fields("道号")
If (a = a1) And (b = b1) And (c = c1) And (d <> d1) Then '仅道号不一样
If Val(d1 - d) = 1 Then
Text1(5) = Text1(5) & "_" & d1
Else
Text1(5).text = Text1(5) & "/" & c1 & d1
End If
ElseIf (a = a1) And (b = b1) And (c <> c1) Then '层号不一样
If Asc(c1) - Asc(c) = 1 And Val(d - d1) = 9 Then
Text1(5).text = Text1(5) & "_" & c1 & d1
Else
Text1(5).text = Text1(5) & "/" & c1 & d1
End If
ElseIf (b <> b1) Then '架号不一样
Text1(5).text = Text1(5) & "/" & a1 & b1 & c1 & d1
End If
End If
If rs.RecordCount > 2 Then '三条以上记录,第一条与第二条比较的结果在于第二条与第三条记录比较的结果比较
For i = 0 To rs.RecordCount - 2
a = rs.Fields("排号")
b = rs.Fields("架号")
c = rs.Fields("层号")
d = rs.Fields("道号")
rs.MoveNext
a1 = rs.Fields("排号")
b1 = rs.Fields("架号")
c1 = rs.Fields("层号")
d1 = rs.Fields("道号")
If (a = a1) And (b = b1) And (c = c1) And (d <> d1) Then '仅道号不一样
If Val(d1 - d) = 1 Then
If i = 0 Then
Text1(5) = a & b & c & d & "_" & d1
Else
Text1(5) = left(Text1(5), Len(Text1(5)) - 3) & "_" & d1
End If
Else
If i = 0 Then
Text1(5).text = a & b & c & d & "/" & c1 & d1
Else
Text1(5).text = Text1(5).text & "/" & c1 & d1
End If
End If
ElseIf (a = a1) And (b = b1) And (c <> c1) Then '层号不一样
If Asc(c1) - Asc(c) = 1 And Val(d - d1) = 9 Then
If i = 0 Then
Text1(5).text = a & b & c & d & "_" & c1 & d1
Else
Text1(5).text = Text1(5) & "_" & c1 & d1
End If
Else
If i = 0 Then
Text1(5).text = a & b & c & d & "/" & c1 & d1
Else
Text1(5).text = Text1(5).text & "/" & c1 & d1
End If
End If
ElseIf (b <> b1) Then '架号不一样
If i = 0 Then
Text1(5).text = a & b & c & d & "/" & a1 & b1 & c1 & d1
Else
Text1(5).text = Text1(5).text & "/" & a1 & b1 & c1 & d1
End If
End If
Next i
End If
Else
Text1(5).text = ""
MsgBox "在导线缓冲架中没发现此文件相关数据,请核查数据!", , "提示"
End If
rs.Close