标题:如何在TXT文件中读取第几行第几到第几个数字?
只看楼主
a59936758
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-4-13
 问题点数:0 回复次数:8 
如何在TXT文件中读取第几行第几到第几个数字?
问题如题目。本人新手。谢谢
搜索更多相关主题的帖子: TXT 数字 文件 
2007-08-16 08:28
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 

Public Const EM_CHARFROMPOS = &HD7
Public Const EM_GETLINECOUNT = &HBA
Public Const EM_GETLINE = &HC4
Public Const EM_LINEINDEX = &HBB
Public Const EM_LINELENGTH = &HC1
Public Const EM_SETSEL = &HB1

Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)
Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long


看看这个函数就知道了


2007-08-16 09:00
a59936758
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-4-13
得分:0 
多谢

咋学学不会.还就偏要学
2007-08-16 09:03
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 

Public Const EM_GETLINE = &HC4
Public Const EM_LINELENGTH = &HC1
Public Const EM_LINEINDEX = &HBB

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Declare Sub RtlMoveMemory Lib "KERNEL32" (lpvDest As Any, lpvSource As Any, ByVal cbCopy As Long)

2. 程序范例:
Sub TB_GetLine(ByVal hWnd As Long, ByVal whichLine As Long, Line As String)

Dim length As Long, bArr() As Byte, bArr2() As Byte, lc As Long

lc = SendMessage(hWnd, EM_LINEINDEX, whichLine, ByVal 0&)

length = SendMessage(hWnd, EM_LINELENGTH, lc, ByVal 0&)

If length > 0 Then
ReDim bArr(length + 1) As Byte,bArr2(length - 1) As Byte
Call RtlMoveMemory(bArr(0), length, 2) '准备一个存储器,传递消息之前先在存储器的前两个字节填入存储器的长度
Call SendMessage(hWnd, EM_GETLINE,whichLine, bArr(0))
Call RtlMoveMemory(bArr2(0), bArr(0), length)
Line = StrConv(bArr2, vbUnicode)
Else
Line = ""
End If
'教程中国.百万教程
End Sub
' 假设要读取 Text1 第 5 行的数据

Dim S As String

Call TB_GetLine( Text1.hWnd, 5, S )

' 传回值 S 即等于第 5 行的数据

( 注:TextBox 的行次是从 0 起算。)


2007-08-16 09:50
缘吇弹
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:地球
等 级:版主
威 望:43
帖 子:3038
专家分:27
注 册:2007-7-2
得分:0 

超级管理


Repeat  Life=Study;Until (death);
2007-08-16 10:17
a59936758
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2007-4-13
得分:0 
顶。正在网上搜区API的使用方法。非常感谢

咋学学不会.还就偏要学
2007-08-16 11:12
随风逐流
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:passerby
等 级:版主
威 望:8
帖 子:4054
专家分:271
注 册:2007-6-13
得分:0 
杀鸡用牛刀......

[url=http://www./html/6/6694/]极道金丹[/url][url=http://www./html/2/2849/]九阴九阳[/url][url=http://www./html/2/2596/]凡人修仙传[/url]
2007-08-16 12:05
心中有剑
Rank: 2
等 级:新手上路
威 望:5
帖 子:611
专家分:0
注 册:2007-5-18
得分:0 

难不成用split (text1,vbcr) 做 哈哈


2007-08-16 12:18
coachard
Rank: 3Rank: 3
等 级:新手上路
威 望:7
帖 子:1251
专家分:0
注 册:2007-8-12
得分:0 
技术含量低一点的可以这样做:

如果数据量不大,则一次性读入一个字符串,再用mid提取出所要的串;如果数据量太大,分次读取,分次统计,取出所要的串!

偶学编程,也许本身就是一个错。。。
2007-08-16 12:33



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-163045-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.337292 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved