for循环中的IF语句有没有更好的地方
Is there a better place for the IF statement in the for loop
For k = 0 To (.Cells(38, 4).Value - 1)
For i = 70 To 73
For j = 0 To 2
If j = 0 Then
bumpvalue = k * (.Cells(39, 4).Value + .Cells(31, 4).Value)
Else
bumpvalue = 0
End If
StartPoint(j) = .Cells(i, 8 + j).Value + bumpvalue
EndPoint(j) = .Cells(i + 1, 8 + j).Value + bumpvalue
Next j
Set lineObj = DWGFile.ModelSpace.AddLine(StartPoint, EndPoint)
Next i
Next k
是否有更好的地方或方法来实现仅在 j = 0 时适用的 "bumpvalue"?
下面的东西告诉我不会飞。
StartPoint(j) = .Cells(i, 8 + j).Value + if j = 0 then k * (.Cells(39, 4).Value + .Cells(31, 4).Value) else 0
您的想法非常接近。请尝试使用 IIf
语句:
StartPoint(j) = .Cells(i, 8 + j).Value + IIf(j = 0, k * (.Cells(39, 4).Value + .Cells(31, 4).Value), 0)
For k = 0 To (.Cells(38, 4).Value - 1)
For i = 70 To 73
For j = 0 To 2
If j = 0 Then
bumpvalue = k * (.Cells(39, 4).Value + .Cells(31, 4).Value)
Else
bumpvalue = 0
End If
StartPoint(j) = .Cells(i, 8 + j).Value + bumpvalue
EndPoint(j) = .Cells(i + 1, 8 + j).Value + bumpvalue
Next j
Set lineObj = DWGFile.ModelSpace.AddLine(StartPoint, EndPoint)
Next i
Next k
是否有更好的地方或方法来实现仅在 j = 0 时适用的 "bumpvalue"?
下面的东西告诉我不会飞。
StartPoint(j) = .Cells(i, 8 + j).Value + if j = 0 then k * (.Cells(39, 4).Value + .Cells(31, 4).Value) else 0
您的想法非常接近。请尝试使用 IIf
语句:
StartPoint(j) = .Cells(i, 8 + j).Value + IIf(j = 0, k * (.Cells(39, 4).Value + .Cells(31, 4).Value), 0)