主题:为什么老是会出错了
Private Sub RichTextBox2_Change()
Dim save As Integer, com As Integer, m As Integer
Static i As Integer
Dim a As String, b As String
i = i + 1
save = Len(RichTextBox2.Text) '将RichTextBox2中内容的长度放入save保存
If save >= i Then
m = i - 1
Else
m = RichTextBox2.SelStart
End If
For j = m To save
RichTextBox2.SelStart = j
k = j + 1
RichTextBox2.SelLength = 1
If Mid(RichTextBox2.Text, k, 1) = Mid(RichTextBox1.Text, k, 1) Then
RichTextBox2.SelColor = vbBlue '如果输入正确,字体颜色变为蓝色
n = n + 1 '统计正确的字数
Label13.Caption = Mid(RichTextBox1.Text, k, 1)
Label14.Caption = Mid(RichTextBox2.Text, k, 1)
Else
RichTextBox2.SelColor = vbRed '如果输入错误,字体颜色变为红色
k = k + 1
End If
Next j
i = save
RichTextBox2.SelStart = i
Label4.Caption = n
End Sub
这个程序在richtextbox2中输入第一行还剩一个的时候颜色变化就开始出现错误了,这是为什么?
Dim save As Integer, com As Integer, m As Integer
Static i As Integer
Dim a As String, b As String
i = i + 1
save = Len(RichTextBox2.Text) '将RichTextBox2中内容的长度放入save保存
If save >= i Then
m = i - 1
Else
m = RichTextBox2.SelStart
End If
For j = m To save
RichTextBox2.SelStart = j
k = j + 1
RichTextBox2.SelLength = 1
If Mid(RichTextBox2.Text, k, 1) = Mid(RichTextBox1.Text, k, 1) Then
RichTextBox2.SelColor = vbBlue '如果输入正确,字体颜色变为蓝色
n = n + 1 '统计正确的字数
Label13.Caption = Mid(RichTextBox1.Text, k, 1)
Label14.Caption = Mid(RichTextBox2.Text, k, 1)
Else
RichTextBox2.SelColor = vbRed '如果输入错误,字体颜色变为红色
k = k + 1
End If
Next j
i = save
RichTextBox2.SelStart = i
Label4.Caption = n
End Sub
这个程序在richtextbox2中输入第一行还剩一个的时候颜色变化就开始出现错误了,这是为什么?