VB6中如何逐行读取文本文件txt中的文本,每次按一次窗体取出下一条信息
2011-11-09
展开全部
Dim MyStr() As String
Private Sub Command1_Click()
Dim t1 As Long, t2 As Long, t3 As Long
Randomize
t1 = Int(UBound(MyStr) * Rnd + 1)
Text1.Text = MyStr(t1)
If UBound(MyStr) < 2 Then Exit Sub
Do
t2 = Int(UBound(MyStr) * Rnd + 1)
Loop While t2 = t1
Text2.Text = MyStr(t2)
If UBound(MyStr) < 3 Then Exit Sub
Do
t3 = Int(UBound(MyStr) * Rnd + 1)
Loop While t3 = t2 Or t3 = t1
Text3.Text = MyStr(t3)
End Sub
Private Sub Form_Load()
Dim fn As Integer, Str As String
ReDim MyStr(0)
fn = FreeFile
Open "C:\TXT.txt" For Input As #fn 'TXT 是文件名
Do Until EOF(fn)
Line Input #fn, Str
If Str <> "" Then
ReDim Preserve MyStr(UBound(MyStr) + 1)
MyStr(UBound(MyStr)) = Str
End If
Loop
Close #fn
End Sub
Private Sub Command1_Click()
Dim t1 As Long, t2 As Long, t3 As Long
Randomize
t1 = Int(UBound(MyStr) * Rnd + 1)
Text1.Text = MyStr(t1)
If UBound(MyStr) < 2 Then Exit Sub
Do
t2 = Int(UBound(MyStr) * Rnd + 1)
Loop While t2 = t1
Text2.Text = MyStr(t2)
If UBound(MyStr) < 3 Then Exit Sub
Do
t3 = Int(UBound(MyStr) * Rnd + 1)
Loop While t3 = t2 Or t3 = t1
Text3.Text = MyStr(t3)
End Sub
Private Sub Form_Load()
Dim fn As Integer, Str As String
ReDim MyStr(0)
fn = FreeFile
Open "C:\TXT.txt" For Input As #fn 'TXT 是文件名
Do Until EOF(fn)
Line Input #fn, Str
If Str <> "" Then
ReDim Preserve MyStr(UBound(MyStr) + 1)
MyStr(UBound(MyStr)) = Str
End If
Loop
Close #fn
End Sub
展开全部
Open Text2.Text For Input As #1
If LOF(1) > 0 Then
RichTextBox1.Text = ""
While Not EOF(1)
x = DoEvents
Line Input #1, Str
RichTextBox1.Text = RichTextBox1.Text + Str + vbCrLf
Wend
End If
Close #1
Open Text2.Text For Input As #1
Str = Input$(LOF(1), #1)
Close #1
Text4.Text = (Len(Str) + bitturn) / (bit + bitturn)
Text3.Text = pc_str
Text5.Text = bit_s + Mid(Str, pc_str * (bit + bitturn) + 1, bit) + bit_e
Text1.Text = Mid(Str, pc_str * (bit + bitturn) + 1, bit)
参考下这是我读取定长时的一个例子
If LOF(1) > 0 Then
RichTextBox1.Text = ""
While Not EOF(1)
x = DoEvents
Line Input #1, Str
RichTextBox1.Text = RichTextBox1.Text + Str + vbCrLf
Wend
End If
Close #1
Open Text2.Text For Input As #1
Str = Input$(LOF(1), #1)
Close #1
Text4.Text = (Len(Str) + bitturn) / (bit + bitturn)
Text3.Text = pc_str
Text5.Text = bit_s + Mid(Str, pc_str * (bit + bitturn) + 1, bit) + bit_e
Text1.Text = Mid(Str, pc_str * (bit + bitturn) + 1, bit)
参考下这是我读取定长时的一个例子
追问
我建立3个文本文档,每次按确定按钮,3个文本框中分辨从txt文本随机取出一行文字文字是以回车结尾的。3个文本框分辨对应txt1txt2txt3. 几年前学过vb现在忘得差不多了,麻烦能帮忙写下吗,谢谢
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
逐行读取文件你应该知道怎么读取了吧,
我得意思是 一次性读取完,存在数组中,按一次数组标加1
我得意思是 一次性读取完,存在数组中,按一次数组标加1
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询