1、运行vb6.0软件。
2、新建一个工程,并且在窗口建立三个commandbutton控件,将其caption依次改为command1显示三角形,command1显示菱形,command1清屏。如图所示!
3、双击任意一个commandbutton控件打开代码窗口,输入代码!
4、Private Sub command1_Click() Dim i As Integer, j As Integer, n As Integer n = V锾攒揉敫al(InputBox("请输入行数!")) For i = 1 To n Print Tab(n + 1 - i); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next iEnd Sub此代码显示等腰三角形!
5、Private Sub Command2_Click() Dim i As Integer, j As Integer, n As Integer n = V锾攒揉敫al(InputBox("请输入行数!")) If n Mod 2 = 1 Then '当为奇数行时执行以下代码。 n = Int((n + 1) / 2) For i = 1 To n Print Tab(n + 1 - i); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next i For i = n - 1 To 1 Step -1 Print Tab(n - i + 1); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next i Else '当为偶数行时执行以下代码。 n = n / 2 For i = 1 To n Print Tab(n + 1 - i); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next i For i = n To 1 Step -1 Print Tab(n - i + 1); For j = 1 To 2 * i - 1 Print "*"; Next j Print Next i End IfEnd Sub
6、Private Sub Command3_Click() Form1.Cls '清屏代码。End Sub