超级玛丽音乐叫什么:请问VB中文本在不断的增加行数,如何将最后一行读出来,

来源:百度文库 编辑:神马品牌网 时间:2024/04/23 16:19:35
现在某个程序往文本里写数字,触发一次,增加一条,然后用VB去读此文本的最后一行数据,如何写,有没有高手知道。
就是现在有一个文本,data.txt,现在有一个程序,每操作他一次,就往里面写一行,如11,23,43,不断的增加,在VB6中,我现在要用每点一次按纽,或是触发一次,就可以将最后一行的数据读到文本框中。

只能用API了:
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 Const EM_GETLINE = &HC4
Private Const EM_GETLINECOUNT = &HBA

Private Type myBuff
byte1 As Byte
byte2 As Byte
sBuff As String * 256
End Type

Private Function GetLastLineText(textbox1 As TextBox) As String
Dim buff As myBuff
Dim astr As String
Dim iLine As Long
Dim iCount As Long

buff.byte1 = 255
iLine = SendMessage(textbox1.hwnd, EM_GETLINECOUNT, 0, 0)
iCount = SendMessage(textbox1.hwnd, EM_GETLINE, iLine - 1, buff)
If iCount > 0 Then
astr = Chr(buff.byte1) + Chr(buff.byte2) + Left$(buff.sBuff, iCount)
Debug.Print astr
End If
GetLastLineText = astr
End Function