第一种:
Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button1.Click
'基本形式,9行9列的输出格式
'可以考虑使用双重循环,行为外部,列为内部
Dim i,j,sum As Integer
Dim ts As String
Label1.Text = ""
For i = 1 To 9 Step 1
For j = 1 To 9 Step 1
sum = i * j
ts = i.ToString() & "*" & j.ToString() & "=" & sum.ToString()
Label1.Text = Label1.Text & ts & Space(10 - Len(ts))
Next
Label1.Text = Label1.Text & vbCrLf
Next
End Sub
Private Sub Button2_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button2.Click
Dim i,sum As Integer ’上三角输出
Dim ts As String
Label1.Text = ""
For i = 1 To 9 Step 1
For j = 1 To i Step 1
sum = i * j
ts = i.ToString() & "*" & j.ToString() & "=" & sum.ToString()
Label1.Text = Label1.Text & ts & Space(10 - Len(ts))
Next
Label1.Text = Label1.Text & vbCrLf
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles Button3.Click
Dim i,sum As Integer
Dim ts As String '下三角输出
Label1.Text = ""
For i = 1 To 9 Step 1
'Label1.Text = Space(i * 10)
For j = i To 9 Step 1
sum = i * j
ts = i.ToString() & "*" & j.ToString() & "=" & sum.ToString()
Label1.Text = Label1.Text & ts & Space(10 - Len(ts))
Next
Label1.Text = Label1.Text & vbCrLf & Space(i * 10)
' Label1.Text = Space(i * 10)
Next
End Sub
End Class
第二种:
Public Class Form1
Private Sub Button1_Click(sender As Object,e As EventArgs) Handles Button1.Click
Dim i,j As Integer
Dim se As String
Label1.Text = ""
For i = 1 To 9 Step 1
For j = 1 To 9 Step 1
se = i & "x" & j & "=" & i * j
Label1.Text &= se & Space(10 - Len(se))
Next
Label1.Text &= vbCrLf
Next
End Sub
Private Sub Button2_Click(sender As Object,e As EventArgs) Handles Button2.Click
Dim i,j As Integer
Dim se As String
Label1.Text = ""
For i = 1 To 9 Step 1
For j = 1 To i Step 1
se = i & "x" & j & "=" & i * j
Label1.Text &= se & Space(10 - Len(se))
Next
Label1.Text &= vbCrLf
Next
End Sub
Private Sub Button3_Click(sender As Object,e As EventArgs) Handles Button3.Click
Dim i,j As Integer
Dim se As String
Label1.Text = ""
For i = 1 To 9 Step 1
For j = i To 9 Step 1
se = i & "x" & j & "=" & i * j
Label1.Text &= se & Space(10 - Len(se))
Next
Label1.Text &= vbCrLf & Space(i * 10)
Next
End Sub
End Class
有疑问可以留言