Hack Forums
[.NET] [VB.NET] File size change notification - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] [VB.NET] File size change notification (/showthread.php?tid=394055)



[VB.NET] File size change notification - codepoet - Apr 30, 2010

The purpose for this code is to turn on the output of the RTS or DTS line of a serial port if the file size changes. I currently use this to turn on a relay that alerts me if I receive new mail in Thunderbird. There is no error checking.

Declarations:
Code
Imports System.IO

Code:
Code
Imports System.IO
'You will get an error if you do not have a file in the path directory that is listed in TextBox1


Public Class Form1
    Dim path As String
    Dim test1 As Integer
    Dim test2 As Integer


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        test2 = test1
    End Sub

    Private Function GetFileSize(ByVal MyFilePath As String) As Long
        Dim MyFile As New FileInfo(MyFilePath)
        Dim FileSize As Long = MyFile.Length
        Return FileSize
    End Function

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Change the number if you want a diffent serial port
        SerialPort1.Open()
        path = TextBox1.Text
        Label1.Text = GetFileSize(path)
        test1 = Label1.Text
        test2 = Label1.Text
    End Sub


    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        path = TextBox1.Text
        Label1.Text = GetFileSize(path)
        test1 = Label1.Text
        If test1 <> test2 Then
            Label2.BackColor = Color.Red
            'This is for RTS as a output
            'SerialPort1.RtsEnable = True
            SerialPort1.DtrEnable = True
        Else
            Label2.BackColor = Color.Black
            'This is for RTS as a output
            'SerialPort1.RtsEnable = False
            SerialPort1.DtrEnable = False
        End If
    End Sub

End Class

orignally written by:Ryan Welsh

If You Like this tutorial,
please check out my other tutorials by clicking ==> here



* - nanoChicken - Apr 30, 2010

or just use the filesystemwatcher class :)


* - codepoet - Apr 30, 2010

well if you use my method its very simple and esay to understand (for noob)


* - Mark Webber's B1tch - Apr 30, 2010

Another great post.

Thanks for sharing mate.


* - codepoet - Apr 30, 2010

no problem... i'm glad you like it

2short


* - codepoet - Apr 30, 2010

If You Like this tutorial,
please check out my other tutorials by clicking ==> here