VB中用循环语句 for 。。next 怎么实现数字金字塔》?

如下情况: 1
222
33333
4444444
33333
222
1
不好意思是这个没显示好!~不是靠开头显示的~! 是前面也有空格的~! 等腰三角形那样~!然后下面也是个等腰三角形~!

'前面加空格,改成这样:
Private Sub Command1_Click()
Dim I As Long, nStr As String, S As Long
S = 4 '显示的最大数字,可修改
Me.Cls: Me.AutoRedraw = True
For I = 1 To S
nStr = String(S - I, " ") & String((I - 1) * 2 + 1, I & "")
Me.Print nStr
Next
For I = S - 1 To 1 Step -1
nStr = String(S - I, " ") & String((I - 1) * 2 + 1, I & "")
Me.Print nStr
Next
End Sub
温馨提示:内容为网友见解,仅供参考
第1个回答  2008-11-05
Private Sub Command2_Click()
Dim tmp, tmp2
For row = 1 To 4
tmp = tmp & Space(6 - row) & String(row * 2 - 1, CStr(row)) & vbCrLf
If row < 4 Then
tmp2 = tmp2 & vbLf & vbCr & String(row * 2 - 1, CStr(row)) & Space(6 - row)
End If
Next row
tmp = tmp & StrReverse(tmp2)
Me.Print tmp
End Sub

'结果
..........1
........222
......33333
....4444444
......33333
........222
..........1

VB中用循环语句 for 。。next 怎么实现数字金字塔》?
Dim I As Long, nStr As String, S As Long S = 4 '显示的最大数字,可修改 Me.Cls: Me.AutoRedraw = True For I = 1 To S nStr = String(S - I, " ") & String((I - 1) * 2 + 1, I & "")Me.Print nStr Next For I = S - 1 To 1 Step -1 nStr = String...

VB代码,数字金字塔
Next i End Sub

相似回答