VB6.0软件
运行vb6.0软件。
新建一个工程,并且在窗口建立三个commandbutton控件,将其caption依次改为command1显示三角形,command1显示菱形, command1清屏。如图所示!
双击任意一个commandbutton控件打开代码窗口,输入代码!
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 iEnd Sub此代码显示等腰三角形!
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 IfEnd Sub
Private Sub Command3_Click() Form1.Cls '清屏代码。End Sub
在考试时先将实际问题转化为数学问题,然后在将数学问题转化为代码!
在这个编写过程中注意将代码写在相应的command1 command2 command3下面。