如何取得文本框中包含指定字符串的行
2008-02-23 07:03:13来源:互联网 阅读 ()
'add a textbox with "multiline=true","scrollbars=2".
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 Function SendMessageByNum Lib "USER32" _
Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function SendMessageByString Lib "USER32" Alias _
"SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam _
As Long, ByVal lParam As String) As Long
Private Const EM_LINEINDEX = &HBB
Private Const EM_GETLINECOUNT = &HBA
Private Const EM_GETLINE = &HC4
Private Const EM_LINELENGTH = &HC1
Function GetLineText(ByVal txtbox As TextBox, ByVal LineIndex As Long) As String '返回指定行的内容
Dim lc As Long, linechar As Long
linechar = SendMessageByNum(txtbox.hWnd, EM_LINEINDEX, LineIndex, 0)
lc = SendMessageByNum(txtbox.hWnd, EM_LINELENGTH, linechar, 0) 1
GetLineText = String(lc 2, 0)
Mid(GetLineText, 1, 1) = Chr(lc And &HFF)
Mid(GetLineText, 2, 1) = Chr(lc \ &H100)
lc = SendMessageByString(txtbox.hWnd, EM_GETLINE, LineIndex, GetLineText)
GetLineText = Left(GetLineText, lc)
End Function
Function getlinewithstr(ByVal txtbox As TextBox, ByVal mystr As String) As String
Dim linecount As Long, temp() As String, i As Long
linecount = SendMessage(txtbox.hWnd, EM_GETLINECOUNT, 0, 0) '返回行数
ReDim temp(1 To linecount)
For i = 1 To linecount
temp(i) = "第" & i & "行:" & GetLineText(txtbox, i - 1) '添加行号
Next
getlinewithstr = Join(Filter(temp, mystr), vbCrLf) ' 字符串过滤
Erase temp
End Function
Private Sub Command1_Click()
MsgBox getlinewithstr(Text1, "CSDN"), 0, "包含“CSDN”的行"
End Sub
Private Sub Form_Load()
Dim a(25) As String, i As Long
For i = 0 To 25
a(i) = String(50, Chr(i 97))
Next
Text1.Text = Join(a, "CSDN")
End Sub
上一篇: 在 VB5.0中编辑数据库和电子表格
下一篇: VB中创建可以输出函数的DLL
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash