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 = Val(InputBox("請輸入行數!"))
For i = 1 To n
Print Tab(n + 1 - i);
For j = 1 To 2 * i - 1
Print "*";
Next j
Print
Next i
End Sub
此程式碼顯示等腰三角形!
5、Private Sub Command2_Click()
If n Mod 2 = 1 Then "當為奇數行時執行以下程式碼。
n = Int((n + 1) / 2)
For i = n - 1 To 1 Step -1
Print Tab(n - i + 1);
Else "當為偶數行時執行以下程式碼。
n = n / 2
For i = n To 1 Step -1
End If
6、Private Sub Command3_Click()
Form1.Cls "清屏程式碼。
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 = Val(InputBox("請輸入行數!"))
For i = 1 To n
Print Tab(n + 1 - i);
For j = 1 To 2 * i - 1
Print "*";
Next j
Print
Next i
End Sub
此程式碼顯示等腰三角形!
5、Private Sub Command2_Click()
Dim i As Integer, j As Integer, n As Integer
n = Val(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 If
End Sub
6、Private Sub Command3_Click()
Form1.Cls "清屏程式碼。
End Sub