两种实现九九乘法表的vb代码

前端之家收集整理的这篇文章主要介绍了两种实现九九乘法表的vb代码前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

第一种:

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

有疑问可以留言

原文链接:https://www.f2er.com/vb/258462.html

猜你在找的VB相关文章