在一个过程中写了一个上千行的if,else语句,编译报错,过程太大,请问一下怎么把这个东西拆分。
过程中最占地方的是以下代码
Private Sub cmdOK_Click()。'过程中的其他语句
。
Dim d() As string Open 11.txt For Output As #1
If UBound(d) <= 3 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2)
ElseIf UBound(d) > 3 And UBound(d) <= 6 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2) & "+"
Print #1, "+ " & d(3) & d(4) & d(5)
ElseIf UBound(d) > 6 And UBound(d) <= 9 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2) & "+"
Print #1, "+ " & d(3) & d(4) & d(5) & "+"
Print #1, "+ " & d(6) & d(7) & d(8)
。。
。。
ElseIf UBound(d) > 498 And UBound(d) <= 501 Then
print #1,。。
。
。
End If
Close 1。。
。。'过程中的其他语句
End Sub
数组d()的元素最多是500,每行打印三个元素,多于一行是此行末尾和下一行的开头有+号,最后一行末尾没有+号。由于把500个全部写出来费时,而且过程太大,不能编译,有什么好的解决办法没有?比如说拆分,把if。。else写成另外一个函数什么的?小妹急求帮忙!
过程中最占地方的是以下代码
Private Sub cmdOK_Click()。'过程中的其他语句
。
Dim d() As string Open 11.txt For Output As #1
If UBound(d) <= 3 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2)
ElseIf UBound(d) > 3 And UBound(d) <= 6 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2) & "+"
Print #1, "+ " & d(3) & d(4) & d(5)
ElseIf UBound(d) > 6 And UBound(d) <= 9 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2) & "+"
Print #1, "+ " & d(3) & d(4) & d(5) & "+"
Print #1, "+ " & d(6) & d(7) & d(8)
。。
。。
ElseIf UBound(d) > 498 And UBound(d) <= 501 Then
print #1,。。
。
。
End If
Close 1。。
。。'过程中的其他语句
End Sub
数组d()的元素最多是500,每行打印三个元素,多于一行是此行末尾和下一行的开头有+号,最后一行末尾没有+号。由于把500个全部写出来费时,而且过程太大,不能编译,有什么好的解决办法没有?比如说拆分,把if。。else写成另外一个函数什么的?小妹急求帮忙!
.. '其它语句
Dim d() As string
Dim i as long ,t as long
i=UBound(d)
i=int(i/3+0.5) Open 11.txt For Output As #1
for t=1 to i if t=1 Then
print Print #1, "MID_STP" & d(0) & d(1) & d(2)
ElseIf t <i then
Print #1, "+ " & d(i*3) & d(i*3+1) & d(i*3+2) & "+"
Else
Print #1, "+ " & d(i*3) & d(i*3+1) & d(i*3+2)
end if Next
...
.. '其它语句
close 1
.. '其它语句
Dim d() As string
Dim i as long ,t as long
i=UBound(d)
i=int(i/3+0.5) Open 11.txt For Output As #1
for t=1 to i if t=1 Then
print Print #1, "MID_STP" & d(0) & d(1) & d(2)
ElseIf t <i then
Print #1, "+ " & d(i*3) & d(i*3+1) & d(i*3+2) & "+"
Else
Print #1, "+ " & d(i*3) & d(i*3+1) & d(i*3+2)
end if Next
...
.. '其它语句
close 1
.. '其它语句
Dim d() As string
Dim i as long ,t as long
i=UBound(d)
i=int(i/3+0.5) Open "11.txt" For Output As #1
for t=1 to i if t=1 Then
Print #1, "MID_STP" & d(0) & d(1) & d(2)
ElseIf t <i then
Print #1, "+ " & d(t*3) & d(t*3+1) & d(t*3+2) & "+"
Else
Print #1, "+ " & d(t*3) & d(t*3+1) & d(t*3+2)
end if Next
...
.. '其它语句
close 1