Private Sub Command1_Click() Dim I As Integer Dim MyInt(1 To 13) As Integer '模拟数据 MyInt(1) = 1 MyInt(2) = 1 MyInt(3) = 2 MyInt(4) = 3 MyInt(5) = 4 MyInt(6) = 9 MyInt(7) = 8 MyInt(8) = 4 MyInt(9) = 5 MyInt(10) = 9 MyInt(11) = 9 MyInt(12) = 9 MyInt(13) = 9
For I = 1 To UBound(MyInt) - 3 If MyInt(I) = MyInt(I + 1) - 1 And MyInt(I) = MyInt(I + 2) - 2 And MyInt(I) = MyInt(I + 3) - 3 Then MsgBox "位置" & I & "-" & I + 3 & "数值递增" ElseIf MyInt(I) = MyInt(I + 1) And MyInt(I) = MyInt(I + 2) And MyInt(I) = MyInt(I + 3) Then MsgBox "位置" & I & "-" & I + 3 & "数值相同" End If Next End Sub
只能遍历了,还能怎样?不过,可能在遍历时,先剔除掉明显不符合的,以加快速度,以一楼的代码为例,加一个判断: For I = 1 To UBound(MyInt) - 3 if myint(i)=myint(i+1)-1 or myint(i)=myint(i+1) then If MyInt(I) = MyInt(I + 1) - 1 And MyInt(I) = MyInt(I + 2) - 2 And MyInt(I) = MyInt(I + 3) - 3 Then MsgBox "位置" & I & "-" & I + 3 & "数值递增" ElseIf MyInt(I) = MyInt(I + 1) And MyInt(I) = MyInt(I + 2) And MyInt(I) = MyInt(I + 3) Then MsgBox "位置" & I & "-" & I + 3 & "数值相同" End If end if Next
For I = 1 To UBound(MyInt) - 3 j=1 do while j<=3 if myint(i+j)=myint(i+j+1)-1 then exit do if j=3 then msgbox i endif end if j=j+1
Dim I As Integer
Dim MyInt(1 To 13) As Integer
'模拟数据
MyInt(1) = 1
MyInt(2) = 1
MyInt(3) = 2
MyInt(4) = 3
MyInt(5) = 4
MyInt(6) = 9
MyInt(7) = 8
MyInt(8) = 4
MyInt(9) = 5
MyInt(10) = 9
MyInt(11) = 9
MyInt(12) = 9
MyInt(13) = 9
For I = 1 To UBound(MyInt) - 3
If MyInt(I) = MyInt(I + 1) - 1 And MyInt(I) = MyInt(I + 2) - 2 And MyInt(I) = MyInt(I + 3) - 3 Then
MsgBox "位置" & I & "-" & I + 3 & "数值递增"
ElseIf MyInt(I) = MyInt(I + 1) And MyInt(I) = MyInt(I + 2) And MyInt(I) = MyInt(I + 3) Then
MsgBox "位置" & I & "-" & I + 3 & "数值相同"
End If
Next
End Sub
只能遍历了,还能怎样?不过,可能在遍历时,先剔除掉明显不符合的,以加快速度,以一楼的代码为例,加一个判断:
For I = 1 To UBound(MyInt) - 3
if myint(i)=myint(i+1)-1 or myint(i)=myint(i+1) then
If MyInt(I) = MyInt(I + 1) - 1 And MyInt(I) = MyInt(I + 2) - 2 And MyInt(I) = MyInt(I + 3) - 3 Then
MsgBox "位置" & I & "-" & I + 3 & "数值递增"
ElseIf MyInt(I) = MyInt(I + 1) And MyInt(I) = MyInt(I + 2) And MyInt(I) = MyInt(I + 3) Then
MsgBox "位置" & I & "-" & I + 3 & "数值相同"
End If
end if
Next
j=1
do while j<=3
if myint(i+j)=myint(i+j+1)-1 then
exit do
if j=3 then
msgbox i
endif
end if
j=j+1
loop
Next!!(没完善)
就这个意思吧,可好!???
应该在else
中写!!