Click here to Skip to main content
15,884,836 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Reset an integer Pin
rudemusik20-Feb-07 13:28
rudemusik20-Feb-07 13:28 
QuestionRead last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:10
bodobe19-Feb-07 10:10 
AnswerRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:14
professionalMarcus J. Smith19-Feb-07 10:14 
GeneralRe: Read last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:23
bodobe19-Feb-07 10:23 
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:29
professionalMarcus J. Smith19-Feb-07 10:29 
GeneralRe: Read last line of logfile and close file immediately Pin
bodobe19-Feb-07 10:40
bodobe19-Feb-07 10:40 
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith19-Feb-07 10:47
professionalMarcus J. Smith19-Feb-07 10:47 
AnswerRe: Read last line of logfile and close file immediately Pin
TwoFaced19-Feb-07 13:06
TwoFaced19-Feb-07 13:06 
I think you can use the a FileStream object to randomly access a file. Here is some code for you to look over. I added a button to the form and when you click the button a messagbox appears displaying the last text to be added to a text file. It keeps track of the last position read so the next time it reads the file it can begin reading it from the last position read. To test it just create a file "c:\test.txt". Run the application and then modify the text file and save it. Clicking the button should display the text you entered. Open the file again and add another line and save it. Again clicking the button should show you the new line of text.
Public Class Form1
    Dim index As Long = -1
    Const file As String = "c:\test.txt"

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'FileInfo object so we can get the file size
        Dim info As New IO.FileInfo(file)

        'How many new bytes since we last checked
        Dim count As Long = info.Length - index

        'File hasn't changed so return
        If count <= 0 Then Return

        'File stream to read file
        Dim stream As IO.FileStream = IO.File.Open(file, IO.FileMode.Open, IO.FileAccess.Read)

        'Buffer to retrieve bytes
        Dim buf(count) As Byte

        'Set the streams position to where we last left off
        stream.Position = index

        'Read the new bytes
        stream.Read(buf, 0, count)

        'clean-up so we don't get in the way of the other program
        stream.Close()
        stream.Dispose()

        'Decoder to convert byte array to string
        Dim textDecoder As New System.Text.ASCIIEncoding
        'The new text
        Dim str As String = textDecoder.GetString(buf)
        'Display new text
        MsgBox(str)

        'Set index to next position
        index = info.Length
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initialize index to the last position in the file
        Dim info As New IO.FileInfo(file)
        index = info.Length
    End Sub
End Class

GeneralRe: Read last line of logfile and close file immediately Pin
bodobe20-Feb-07 20:43
bodobe20-Feb-07 20:43 
GeneralRe: Read last line of logfile and close file immediately Pin
TwoFaced20-Feb-07 21:32
TwoFaced20-Feb-07 21:32 
GeneralRe: Read last line of logfile and close file immediately Pin
Marcus J. Smith23-Feb-07 5:20
professionalMarcus J. Smith23-Feb-07 5:20 
QuestionVB6.0 - Common Dialog "ShowSave" method to get a Folder? Pin
ChemmieBro19-Feb-07 9:55
ChemmieBro19-Feb-07 9:55 
QuestionEncrypted source files Pin
Fernando A. Gomez F.19-Feb-07 8:38
Fernando A. Gomez F.19-Feb-07 8:38 
AnswerRe: Encrypted source files Pin
Dave Kreskowiak19-Feb-07 9:33
mveDave Kreskowiak19-Feb-07 9:33 
GeneralRe: Encrypted source files Pin
Fernando A. Gomez F.19-Feb-07 10:43
Fernando A. Gomez F.19-Feb-07 10:43 
QuestionUseing Serial Port Pin
Max Bayne19-Feb-07 8:13
Max Bayne19-Feb-07 8:13 
AnswerRe: Useing Serial Port Pin
Ankur.Bakliwal19-Feb-07 17:35
Ankur.Bakliwal19-Feb-07 17:35 
Questiondisable groupbox Pin
jds120719-Feb-07 7:56
jds120719-Feb-07 7:56 
AnswerRe: disable groupbox Pin
Marcus J. Smith19-Feb-07 8:19
professionalMarcus J. Smith19-Feb-07 8:19 
AnswerRe: disable groupbox Pin
TwoFaced19-Feb-07 8:23
TwoFaced19-Feb-07 8:23 
QuestionCONVERSION OF VB CODE TO JAVASCRIPT Pin
soadfreak19-Feb-07 7:48
soadfreak19-Feb-07 7:48 
AnswerRe: CONVERSION OF VB CODE TO JAVASCRIPT Pin
Christian Graus19-Feb-07 8:53
protectorChristian Graus19-Feb-07 8:53 
Questionadding new record and saving in VB.NET Pin
7prince19-Feb-07 6:15
7prince19-Feb-07 6:15 
AnswerRe: adding new record and saving in VB.NET Pin
Marcus J. Smith19-Feb-07 8:24
professionalMarcus J. Smith19-Feb-07 8:24 
GeneralRe: adding new record and saving in VB.NET Pin
7prince19-Feb-07 8:46
7prince19-Feb-07 8:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.