如图中的星号图形怎么编写,请大虾帮忙,VB的
如图中的星号图形怎么编写,请大虾帮忙,VB的
Option Explicit
Private Sub Form_Click()
Dim iTab As Integer, i As Integer, iLevel As Integer
Dim j As Integer, k As Integer, strTmp As String
iTab = 6
iLevel = 1
For i = 1 To 6
'打印星形
strTmp = ""
If iLevel <= 3 Then
strTmp = String(iLevel, "★")
Else
k = k + 1
For j = 1 To 3
strTmp = strTmp & "★" & String(k, " ")
Next
End If
Print Tab(iTab); strTmp
iTab = iTab - 1
iLevel = iLevel + 1
Next
End Sub
Option Explicit
Private Sub Form_Click() '点击窗体时,执行以下代码
Dim iTab As Integer, i As Integer, iLevel As Integer 'iLevel 为当前的行数
Dim j As Integer, k As Integer, strTmp As String
iTab = 6 '最初设置为输出 6 个制表符
iLevel = 1 '第一行
For i = 1 To 6 '循环六次,即共输出六行字符
'打印星形
strTmp = ""
If iLevel <= 3 Then '如果当前行数是三行或未到三行
strTmp = String(iLevel, "★") '根据 iLevel 的值打印若干星形(例如 iLevel = 1 时,打印一个★)
Else '如果当前行数不止三行
k = k + 1 '★与★之间的空格数量加1
For j = 1 To 3 '循环三次
strTmp = strTmp & "★" & String(k, " ") '先输出一个★,然后输出 k 个空格
Next
End If
Print Tab(iTab); strTmp 'Tab(iTab)意思是输出 iTab 个制表符,然后输出 strTmp
iTab = iTab - 1 '输出制表符数量减1
iLevel = iLevel + 1 '行数加1
Next
End Sub
qq 155302324
两个循环一个打行一个打列