选择显示字体大小

vb中快速读取 textbox 第 n 行的资料


  textbox 是以 vbcr+vblf 为分行符号, 如果我们要逐一读取 textbox 每一行,无非是寻找 vbcr+vblf 的所在位置, 然后取出每一行的字串, 不过这个方法真的不快,而且如果我们要读取第 n 行资料, 还是要从第 1、2、┅n-1 行逐一读起, 实在麻烦。

还好 windows api 提供有读取 textbox 第 n 行的功能, 细节如下:

1. api 的声明:

const em_getline = &hc4
const em_linelength = &hc1
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)

注:如果以上的声明放在「一般模块」底下, 应在 const 之前加上 public 保留字, 并且将 private 保留字去掉。

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 起算。


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons