VB初学者求大神帮帮忙 要用循环结构的方法做 谢谢了
发布网友
发布时间:2023-12-21 23:18
我来回答
共1个回答
热心网友
时间:2024-01-19 02:09
Private Sub Command1_Click() '制作99乘法表
Dim i, j As Integer
For i = 1 To 9
For j = 1 To 3
Text1.Text = Text1.Text & j & "x" & i & "=" & i * j & " "
Next
Text1.Text = Text1.Text & vbCrLf
Next
Text1.Text = Text1.Text & vbCrLf
For i = 1 To 9
For j = 4 To 6
Text1.Text = Text1.Text & j & "x" & i & "=" & i * j & " "
Next
Text1.Text = Text1.Text & vbCrLf
Next
Text1.Text = Text1.Text & vbCrLf
For i = 1 To 9
For j = 7 To 9
Text1.Text = Text1.Text & j & "x" & i & "=" & i * j & " "
Next
Text1.Text = Text1.Text & vbCrLf
Next
End Sub
Private Sub Command1_Click() '求和
If Val(Text1.Text) = 0 Then
Exit Sub
End If
Dim i, j As Integer
Dim sum1, sum2 As Integer
For i = 1 To Val(Text1.Text)
sum1 = sum1 + i
Next
i = 1
Do
If i Mod 2 = 0 Then
sum2 = sum2 + i
End If
If i = Val(Text1.Text) Then
Exit Do
End If
i = i + 1
Loop
Label2.Caption = "总和为:" & sum1 & Chr(13) & "偶数和为:" & sum2
End Sub
Private Sub Command1_Click() '阶乘
Dim i, j As Integer
j = 1
For i = 1 To Val(Text1.Text)
j = j * i
Next
Label2.Caption = Val(Text1.Text) & "的阶乘结果为:" & j
End Sub