题库 高中信息

题干

   (加试题)小马正在看一本侦探小说,想了解其中一段案情的解析,却发现了一串字符“#2017-2018go:)”,并附有文字提示:①答案所在的页码是这串字符中最大数字字串(若值相同则取后面的数字字串)的起始位置*10+结束位置②答案所在行号是最大数值除以100的余数。例如:“#17a18#”字符串中,最大数字字串“18”,起始位置是5,结束位置是6,其页码是56,行号是18。小马编写了一个VB程序帮他寻找答案,程序运行界面如图所示。在文本框Text1中输入这段字符串s1,单击“揭秘”按钮Command1,在文本框Text2中输出页码,在Text3中输出行号。


实现上述功能的VB程序代码如下,但划线处代码有错,请改正。
Private Sub Command1_Click()
Dim s1 As String, s2 As String
Dim ch As String, ch2 As String
Dim max As Double
Dim n As Integer, page As Integer
Dim iAs Integer, j As Integer
s1=Text1.text: s2 = ""
n = Len(s1)
i = 1: max = 0
Do While i<= n
ch = Mid(s1, i, 1)
If ch>= "0" And ch<= "9" Then
j = i
ch2 = Mid(s1, j, 1)
Do While ch2 >= "0" And ch2 <= "9"
j = j + 1
ch2 = Mid(s1, j, 1)
Loop
s2 = Mid(s1, 1, j–i) '(1)改正:________________
If Val(s2) < max Then    '(2)改正:_______________
max = Val(s2)
page = i * 10 + j - 1
Text2.Text = Str(page)
Text3.Text = Str(max Mod 100)
End If
i = j
End If
i = i + 1
Loop
End Sub
上一题 下一题 0.99难度 填空题 更新时间:2019-05-06 12:23:50

答案(点此获取答案解析)