'在窗体上添加一TextBox,MultiLine设为True,添加一Command1按钮,将如下代码复制到 '窗体代码中,点击Command1看看效果:Option ExplicitPrivate Sub Command1_Click() Call Draw(5, "1") End Sub'nMaxLines: 最大的层数; strChar:你要画的字符,如:“1”,“*”等 Private Function Draw(ByVal nMaxLines As Integer, ByVal strChar As String) Dim i As Integer, j As Integer Dim strTmp As String, strSpace As String If nMaxLines <= 0 Then Exit Function
Text1.Text = "" For i = 1 To nMaxLines strSpace = Space(nMaxLines - i) strTmp = "" For j = 1 To 2 * i - 1 If j Mod 2 = 0 Then strTmp = strTmp & " " Else strTmp = strTmp & strChar End If Next j strTmp = strSpace & strTmp & strSpace Text1.Text = Text1.Text & strTmp & vbCrLf Next i
'窗体代码中,点击Command1看看效果:Option ExplicitPrivate Sub Command1_Click()
Call Draw(5, "1")
End Sub'nMaxLines: 最大的层数; strChar:你要画的字符,如:“1”,“*”等
Private Function Draw(ByVal nMaxLines As Integer, ByVal strChar As String)
Dim i As Integer, j As Integer
Dim strTmp As String, strSpace As String
If nMaxLines <= 0 Then Exit Function
Text1.Text = ""
For i = 1 To nMaxLines
strSpace = Space(nMaxLines - i)
strTmp = ""
For j = 1 To 2 * i - 1
If j Mod 2 = 0 Then
strTmp = strTmp & " "
Else
strTmp = strTmp & strChar
End If
Next j
strTmp = strSpace & strTmp & strSpace
Text1.Text = Text1.Text & strTmp & vbCrLf
Next i
End Function
ME.PRINT " 1 "
ME.PRINT " 1 1 "
ME.PRINT " 1 1 1"
ME.PRINT " 1 1 1 1"
ME.PRINT " 1 1 1 1 1"
唉,好久没看到过这么简单的题啦。
ME.PRINT " 1 1 1 1 1"
ME.PRINT " 1 1 1 1"
ME.PRINT " 1 1 1"
ME.PRINT " 1 1 "
ME.PRINT " 1 "