Public Class FileScan Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click FDBrowse.ShowDialog() Me.TextBox1.Text = FDBrowse.SelectedPath.ToString End Sub Private Sub logEvent(ByVal EventThatOccured As String) lbEvents.Items.Insert(0, EventThatOccured) End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Me.TextBox1.Text = "" Then Me.TextBox2.Text = "Cannot check as no dierctory listed" Else 'connect to D2000 and get consignment / reference list Dim reader As Odbc.OdbcDataReader Dim lsRef, lsConsign As String 'lcerror Using connect As New Odbc.OdbcConnection("dsn=bdata") Using connectCmd As New Odbc.OdbcCommand("select * from xdref", connect) connect.ConnectionTimeout = 1 connect.Open() logEvent("connecting") Try reader = connectCmd.ExecuteReader() 'any data returned? If reader.HasRows Then 'process list and check for export file While reader.Read() 'if file does not exist create lsConsign = reader.Item(1) lsRef = reader.Item(2) Dim checkFile As String = Me.TextBox1.Text + "\" + Trim(lsRef) + ".TXT" logEvent("Exist?: " + checkFile) If My.Computer.FileSystem.FileExists(checkFile) Then logEvent("Already exist: " + checkFile) Else ' create file logEvent("Writing: " + checkFile) Using objStreamWriter As New System.IO.StreamWriter(checkFile) objStreamWriter.WriteLine(Trim(lsConsign)) objStreamWriter.Close() Me.Label7.Text = checkFile End Using End If End While End If logEvent("Closing reader and connection") reader.Close() connect.Close() ' theres been a problem Catch ex As Exception logEvent("Error when connecting or reading/writing data") connect.Close() End Try End Using 'end using command End Using 'end using the connection Me.Label3.Text = Now() End If End Sub ' start / stop button Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If Me.TextBox1.Text = "" Then MsgBox("Please set the folder to browse before starting the server.", MsgBoxStyle.OkOnly) Return End If If Me.Timer1.Enabled = False Then Me.Timer1.Enabled = True Me.Button2.Text = "Stop" Else Me.Timer1.Enabled = False Me.Button2.Text = "Start" End If End Sub Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged If Me.TextBox2.Text = "" Then Me.Timer1.Interval = 5000 Return End If If Val(Me.TextBox2.Text) <= 0 Or Val(Me.TextBox2.Text) > 60 Then MsgBox("Invalid entry. Value must be between 0 and 60.", MsgBoxStyle.OkOnly) Return End If Me.Timer1.Interval = Val(Me.TextBox2.Text) * 1000 End Sub Public Sub New() ' This call is required by the Windows Form Designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. End Sub Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged End Sub Protected Overrides Sub Finalize() MyBase.Finalize() End Sub Private Sub FileScan_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated Dim filereader As String, data(50) As String filereader = My.Computer.FileSystem.ReadAllText("filescan.ini") data = Split(filereader, ",") Me.TextBox1.Text = data(0) Me.TextBox2.Text = data(1) End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click My.Computer.FileSystem.WriteAllText("filescan.ini", Trim(Me.TextBox1.Text) + "," + Trim(Me.TextBox2.Text), False) End Sub Private Sub FileScan_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class