Private Sub Command1_Click()
Dim N As Integer
N = 6 '需要输出的行数
'如果前面没有空格
For i = 1 To 2 * N + 1
For j = 1 To Abs(i - N - 1) * 2 + 1
If j = 1 Or j = Abs(i - N - 1) * 2 + 1 Then
Print "*";
Else
Print "#";
End If
Next
Print
Next
Print
Print
'如果是左右对称
For i = 1 To 2 * N + 1
Print Tab(N - Abs(N - i + 1) + 1);
For j = 1 To Abs(i - N - 1) * 2 + 1
If j = 1 Or j = Abs(i - N - 1) * 2 + 1 Then
Print "*";
Else
Print "#";
End If
Next
Next
End Sub
楼上考虑的很全面
可以简化的.
一般的情况,可以节省的,就不要循环嵌套
iif函数的使用,可以简化代码而且看起来很清晰
for i=-5 to 5
print "*" & string(2*abs(i)-1) * iif(i=0,0,1) & iif(i=0,"","*")
next