Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

.NET 

[VB.NET] File size change notification

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
PHP & .NET Contributor.
or just use the filesystemwatcher class :)
well if you use my method its very simple and esay to understand (for noob)
PHP & .NET Contributor.
Another great post.

Thanks for sharing mate.
no problem... i'm glad you like it

2short
PHP & .NET Contributor.
If You Like this tutorial,
please check out my other tutorials by clicking ==> here
PHP & .NET Contributor.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by sonnyJul 2, 2021 02:17 PM 0 223 Jul 2, 2021 02:17 PM
Last Post: sonny
[C#] by zxPhantomBladeJul 17, 2020 06:38 PM 3 157 Jul 17, 2020 06:38 PM
Last Post: Accord
[C] by PhantomBladeJul 11, 2020 01:21 PM 10 202 Jul 11, 2020 01:21 PM
Last Post: HFDone