VB读取文本内容 高手来

来源:百度知道 编辑:UC知道 时间:2024/05/27 12:38:53
用VB写一个读文本的程序
在目录C:\123下有文本文档10个 分别是
A.TXT B.TXT ... J.TXT
每个文档内有8行内容 每行是2个数字
例如
A.TXT内
01
02
03
04
05
06
07
08

程序中有3个文本框,和三个文字标签
每个文本框内只能输入2个字符 输入结束自动转入下一个文本框

我在第一个文本框中输入 A2
则第一个文字标签 显示A.TXT中的第二行的内容

依次类推
给我源代码行么?都100分了

我给你的这个源代码没有加入出错功能,如果你自己不会,再联系我,功能上能满足你的要求。
Dim res As String

Private Sub Text1_Change()
If Len(Text1.Text) = 2 Then
Call check(Text1.Text)
Label1.Caption = res
Text2.SetFocus

ElseIf Len(Text1.Text) > 2 Then
Text1.Text = ""
Text1.SetFocus
End If
End Sub

Private Sub Text2_Change()
If Len(Text2.Text) = 2 Then
Call check(Text2.Text)
Label2.Caption = res
Text3.SetFocus
ElseIf Len(Text2.Text) > 2 Then
Text2.Text = ""
Text2.SetFocus
End If
End Sub

Private Sub Text3_Change()
If Len(Text3.Text) = 2 Then
Call check(Text3.Text)
Label3.Caption = res
ElseIf Len(Text3.Text) > 2 Then
Text3.Text = ""
Text3.SetFocus
End If
End Sub

Sub check(temp As String)
Dim a As Long
Open "c:\123\" & Left$(temp, 1) & ".txt" For Input As #1
a = Right$(