vb文件读入并显示到textbox里代码怎么写
是这样的,点下按钮Command3,把c盘根目录下的3d.txt文件里面的数据读入并显示到text1里面。c:\3d.txt的内容如下:2011141,915,304,1...
是这样的,点下按钮Command3,把c盘根目录下的3d.txt文件里面的数据读入并显示到text1里面。
c:\3d.txt的内容如下:
2011141,915,304,1,1
2011142,789,109,1,1
2011143,058,559,1,1
2011144,644,820,1,1
2011145,494,738,1,1
需要最后三行的数据读入并显示到text1里面,格式像这样:
201143,058,559
201144,644,820
201145,494,738
这个顺序问题让我头疼的厉害,求高手给代码,能运行正确积分双手奉上,谢谢!
3d.txt里有很多数据的,要取最后三行的顺序排列。顺序要对
2011121,220,794,1,1
2011122,555,856,1,1
2011123,769,536,1,1
2011124,791,821,1,1
2011125,006,507,1,1
2011126,055,726,1,1
2011127,467,536,1,1
2011128,691,300,1,1
2011129,082,249,1,1
2011130,038,700,1,1
2011131,454,403,1,1
2011132,418,708,1,1
2011133,016,544,1,1
2011134,225,867,1,1
2011135,809,366,1,1
2011136,559,255,1,1
2011137,958,867,1,1
2011138,475,912,1,1
2011139,265,444,1,1
2011140,819,849,1,1
2011141,915,304,1,1
2011142,789,109,1,1
2011143,058,559,1,1
2011144,644,820,1,1
2011145,494,738,1,1 展开
c:\3d.txt的内容如下:
2011141,915,304,1,1
2011142,789,109,1,1
2011143,058,559,1,1
2011144,644,820,1,1
2011145,494,738,1,1
需要最后三行的数据读入并显示到text1里面,格式像这样:
201143,058,559
201144,644,820
201145,494,738
这个顺序问题让我头疼的厉害,求高手给代码,能运行正确积分双手奉上,谢谢!
3d.txt里有很多数据的,要取最后三行的顺序排列。顺序要对
2011121,220,794,1,1
2011122,555,856,1,1
2011123,769,536,1,1
2011124,791,821,1,1
2011125,006,507,1,1
2011126,055,726,1,1
2011127,467,536,1,1
2011128,691,300,1,1
2011129,082,249,1,1
2011130,038,700,1,1
2011131,454,403,1,1
2011132,418,708,1,1
2011133,016,544,1,1
2011134,225,867,1,1
2011135,809,366,1,1
2011136,559,255,1,1
2011137,958,867,1,1
2011138,475,912,1,1
2011139,265,444,1,1
2011140,819,849,1,1
2011141,915,304,1,1
2011142,789,109,1,1
2011143,058,559,1,1
2011144,644,820,1,1
2011145,494,738,1,1 展开
2个回答
展开全部
Private Sub Command3_Click()
Dim RowNo As Integer'用来记录读到那一行了
Dim FileNo As Integer
Dim str() As String '定义一个字符串数组
Dim str_three As String '用来记录结果
FileNo = FreeFile() '获取一个未使用的文件号
Open "C:\3d.txt" For Input As #FileNo
While Not EOF(FileNo)
Dim str_Read As String
ReDim Preserve str(RowNo)
Line Input #FileNo, str(RowNo) '读取一行
RowNo = RowNo + 1
Wend
str_three = Replace(str(RowNo - 3), ",1,1", "") & vbCrLf
str_three = str_three & Replace(str(RowNo - 2), ",1,1", "") & vbCrLf
str_three = str_three & Replace(str(RowNo - 1), ",1,1", "") & vbCrLf
Me.Text1.Text = str_three
Close #FileNo
End Sub
'注意自己要保证文件的内容行数大于3
Dim RowNo As Integer'用来记录读到那一行了
Dim FileNo As Integer
Dim str() As String '定义一个字符串数组
Dim str_three As String '用来记录结果
FileNo = FreeFile() '获取一个未使用的文件号
Open "C:\3d.txt" For Input As #FileNo
While Not EOF(FileNo)
Dim str_Read As String
ReDim Preserve str(RowNo)
Line Input #FileNo, str(RowNo) '读取一行
RowNo = RowNo + 1
Wend
str_three = Replace(str(RowNo - 3), ",1,1", "") & vbCrLf
str_three = str_three & Replace(str(RowNo - 2), ",1,1", "") & vbCrLf
str_three = str_three & Replace(str(RowNo - 1), ",1,1", "") & vbCrLf
Me.Text1.Text = str_three
Close #FileNo
End Sub
'注意自己要保证文件的内容行数大于3
展开全部
Private Sub Form_Load()
Dim tmp As String, a(2) As String
Dim x As Integer, y As String
Open "c:\3d.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
If x = 3 Then
a(0) = a(1)
a(1) = a(2)
a(2) = tmp
Else
a(x) = tmp
x = x + 1
End If
Loop
Close #1
text1.Text = Replace(Join(a, vbCrLf), ",1,1", "")
End Sub
Dim tmp As String, a(2) As String
Dim x As Integer, y As String
Open "c:\3d.txt" For Input As #1
Do While Not EOF(1)
Line Input #1, tmp
If x = 3 Then
a(0) = a(1)
a(1) = a(2)
a(2) = tmp
Else
a(x) = tmp
x = x + 1
End If
Loop
Close #1
text1.Text = Replace(Join(a, vbCrLf), ",1,1", "")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询