Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
File size change notification
Author:
Ryan Welsh
E-mail:
Click to e-mail author
Submitted:
3/24/2010
Version:
VB 2008
Compatibility:
VB 2008
Category:
File Manipulation
Views:
8561
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:
Imports System.IO
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
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement