修改VB程序中的错误代码
一、改错题【要求】1.新建工程,输入以下代码,改正程序中的错误;2.改错时,可调整个别语句的位置,但不得增加或删除语句;3.以Myfrm1和Myprj1为文件名保存窗体和...
一、 改错题
【要求】
1. 新建工程,输入以下代码,改正程序中的错误;
2. 改错时,可调整个别语句的位置,但不得增加或删除语句;
3. 以Myfrm1和Myprj1为文件名保存窗体和工程并提交。
【题目】
字符串“642138579”首尾相联形成一个数字环,依次在数字环中顺序截取2位数、3位数、4位数,使所截取得到的前两个数相乘等于第三个数。例如:42*138=5796。
Option Explicit
Public a(9) As Integer
Private Sub Form_Click()
Const s As String = "642138579"
Dim i As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For i = 1 To 9
a(i) = Mid(s, i, 1)
Next
For i = 1 To 9
Idx = i
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next i
End Sub
Private Sub Mut(ByVal Idx As Integer, n As Integer, M As Long)
Dim i As Integer
For i = 1 To n
M = M * 10 + a(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = 0
Next i
End Sub 展开
【要求】
1. 新建工程,输入以下代码,改正程序中的错误;
2. 改错时,可调整个别语句的位置,但不得增加或删除语句;
3. 以Myfrm1和Myprj1为文件名保存窗体和工程并提交。
【题目】
字符串“642138579”首尾相联形成一个数字环,依次在数字环中顺序截取2位数、3位数、4位数,使所截取得到的前两个数相乘等于第三个数。例如:42*138=5796。
Option Explicit
Public a(9) As Integer
Private Sub Form_Click()
Const s As String = "642138579"
Dim i As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For i = 1 To 9
a(i) = Mid(s, i, 1)
Next
For i = 1 To 9
Idx = i
Call Mut(Idx, 2, N1)
Call Mut(Idx, 3, N2)
Call Mut(Idx, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next i
End Sub
Private Sub Mut(ByVal Idx As Integer, n As Integer, M As Long)
Dim i As Integer
For i = 1 To n
M = M * 10 + a(Idx)
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = 0
Next i
End Sub 展开
1个回答
展开全部
Option Explicit
Dim a(9) As Integer
Private Sub Form_Click()
Const s As String = "642138579"
Dim i As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For i = 1 To 9
a(i) = Mid(s, i, 1)
Next
For i = 1 To 9
Idx = i
Call Mut(Idx, 2, N1)
Call Mut(Idx + 2, 3, N2)
Call Mut(Idx + 5, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next i
End Sub
Private Sub Mut(ByVal Idx As Integer, n As Integer, M As Long)
Dim i As Integer
M = 0
For i = 1 To n
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = M * 10 + a(Idx)
Next i
End Sub
Dim a(9) As Integer
Private Sub Form_Click()
Const s As String = "642138579"
Dim i As Integer, N3 As Long
Dim Idx As Integer, N1 As Long, N2 As Long
For i = 1 To 9
a(i) = Mid(s, i, 1)
Next
For i = 1 To 9
Idx = i
Call Mut(Idx, 2, N1)
Call Mut(Idx + 2, 3, N2)
Call Mut(Idx + 5, 4, N3)
If N3 = N1 * N2 Then
Print N1; "*"; N2; "="; N3
End If
Next i
End Sub
Private Sub Mut(ByVal Idx As Integer, n As Integer, M As Long)
Dim i As Integer
M = 0
For i = 1 To n
Idx = Idx + 1
If Idx > 9 Then Idx = 1
M = M * 10 + a(Idx)
Next i
End Sub
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询