vb 文本文件的读取问题(急)
请高手帮小弟指点一下下面的二个VB6.0编程问题:两个txt文件(f1.txt和s2.txt)里分别存着若干行数据,一个Command1控件,两个text控件(text1...
请高手帮小弟指点一下下面的二个VB6.0编程问题:
两个txt文件(f1.txt和s2.txt)里分别存着若干行数据,一个Command1控件,两个text控件(text1和text2),如何编写command1的Click事件,每单击一次command1,就顺序从f1.txt文件中读取一行显示在text1中,随机从s2.txt文件中读取一行显示在text2中?
例如f1.txt里面存着:
111
222
333
444
s2.txt里面存着:
aaa
bbb
ccc
ddd
第一次单击command1时,text1中显示111,text2中随机显示一行;
第二次单击command1时,text1中显示222,text2中随机显示一行;
第三次单击command1时,text1中显示333,text2中随机显示一行;
第四次单击command1时,text1中显示444,text2中随机显示一行; 展开
两个txt文件(f1.txt和s2.txt)里分别存着若干行数据,一个Command1控件,两个text控件(text1和text2),如何编写command1的Click事件,每单击一次command1,就顺序从f1.txt文件中读取一行显示在text1中,随机从s2.txt文件中读取一行显示在text2中?
例如f1.txt里面存着:
111
222
333
444
s2.txt里面存着:
aaa
bbb
ccc
ddd
第一次单击command1时,text1中显示111,text2中随机显示一行;
第二次单击command1时,text1中显示222,text2中随机显示一行;
第三次单击command1时,text1中显示333,text2中随机显示一行;
第四次单击command1时,text1中显示444,text2中随机显示一行; 展开
2个回答
展开全部
Dim N1 As Integer, N2 As Integer, Str1() As String, Str2() As String
Private Sub Command1_Click()
Static i As Integer
If i >= N1 Then i = 0
Randomize
Text1.Text = Str1(i)
Text2.Text = Str2(Int(Rnd * N2))
i = i + 1
End Sub
Private Sub Form_Load()
Open "c:\1.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve Str1(N1) As String
Input #1, Str1(N1)
N1 = N1 + 1
Loop
Close
Open "c:\2.txt" For Input As #2
Do Until EOF(2)
ReDim Preserve Str2(N2) As String
Input #2, Str2(N2)
N2 = N2 + 1
Loop
Close
End Sub'改过了....
Private Sub Command1_Click()
Static i As Integer
If i >= N1 Then i = 0
Randomize
Text1.Text = Str1(i)
Text2.Text = Str2(Int(Rnd * N2))
i = i + 1
End Sub
Private Sub Form_Load()
Open "c:\1.txt" For Input As #1
Do Until EOF(1)
ReDim Preserve Str1(N1) As String
Input #1, Str1(N1)
N1 = N1 + 1
Loop
Close
Open "c:\2.txt" For Input As #2
Do Until EOF(2)
ReDim Preserve Str2(N2) As String
Input #2, Str2(N2)
N2 = N2 + 1
Loop
Close
End Sub'改过了....
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询