修改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
展开
 我来答
wjjsuda
2008-12-19 · TA获得超过422个赞
知道小有建树答主
回答量:966
采纳率:0%
帮助的人:362万
展开全部
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
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式