Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As LongConst EM_GETLINECOUNT = &HBA Public Function LineCount(txtBox As TextBox) As Long LineCount = SendMessage(txtBox.hwnd, EM_GETLINECOUNT, 0&, 0&)End Function Private Sub Command1_Click() MsgBox LineCount(Text1)End Sub
n = len(strFile) - len(replace(strFile, vbcrlf, "")) + 1
up 就是看看换行标志符号vbcrlf有多少个
dim strx as string dim hangshu as long'行数 open "C:\txt1.txt" for input as 1 hangshu = 0 do until eof(1) line input #1,strx'依次读出一行 hangshu = hangshu + 1 loop
如果是chr(13)
则行数+1
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As LongConst EM_GETLINECOUNT = &HBA Public Function LineCount(txtBox As TextBox) As Long LineCount = SendMessage(txtBox.hwnd, EM_GETLINECOUNT, 0&, 0&)End Function
Private Sub Command1_Click() MsgBox LineCount(Text1)End Sub
就是看看换行标志符号vbcrlf有多少个
dim hangshu as long'行数
open "C:\txt1.txt" for input as 1
hangshu = 0
do until eof(1)
line input #1,strx'依次读出一行
hangshu = hangshu + 1
loop
filecontext = filecontext & strx & chr(13) & chr(10)