17438.html

来自「VB技巧问答10000例,是一个教程」· HTML 代码 · 共 23 行

HTML
23
字号
<html>  <head>    <title>sorry 少加了几行 code, 请入内看</title>  </head>  <body bgcolor="#FFFFFF" vlink="#808080">    <center>      <h1>sorry 少加了几行 code, 请入内看</h1>    </center><hr size=7 width=75%><hr size=7 width=75%><p>Posted by Albert on August 18, 1999 at 10:57:58:<p>In Reply to: <a href="17437.html">Why !? 我用如下的 code, but run time 时会有 语法错误 at : Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String</a> posted by Albert on August 18, 1999 at 10:55:21:<p>Private Sub Command1_Click()<br>Dim str5 As String<br>Dim LineCnt As Long<p>LineCnt = TextBoxLineCnt(Text1)<br>str5 = GetaLine(Text1, LineCnt) '取得第二行的字串,以0为基底<p>Debug.Print str5<br>End Sub<p><br>: Option Explicit<br>: Const EM_GETLINE = &HC4<br>: Public Const EM_GETLINECOUNT = &HBA<br>: Declare Function SendMessage Lib "user32" Alias "SendMessageA" _<br>:         (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _<br>:          lParam As Any) As Long<br>:  Public Function GetaLine(Text1 As TextBox, ByVal ntx As Long) As String<br>:  Dim str5(255) As Byte '如果您的字串 > 255 byte请自行增加该Byte Array<br>:  Dim str6 As String, i As Long<br>:  <br>:     str5(0) = 255 '字串的前两个Byte存该字串的最大长度 str5(0) = 255<br>:     i = SendMessage(Text1.hwnd, EM_GETLINE, ntx, str5(0))<br>:     If i = 0 Then<br>:         GetaLine = ""<br>:     Else<br>:         str6 = StrConv(str5, vbUnicode)<br>:         GetaLine = Left(str6, InStr(1, str6, Chr(0)) - 1)<br>:     End If<br>: End Function<p>: <br>: Option Explicit<br>: Public Function TextBoxLineCnt(ctl As TextBox) As Long<br>: TextBoxLineCnt = SendMessage(ctl.hwnd, EM_GETLINECOUNT, 0, 0)<br>: End Function<p><br><br><hr size=7 width=75%><p><a name="followups">Follow Ups:</a><br><ul><!--insert: 17438--></ul><!--end: 17438--><br><hr size=7 width=75%><p></body></html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?