Blake81
Well-known member
This program is supposed to watch a folder and display Form2 (with the text of Label1 in Form2 equal to specific text) when a file contained in a String Collection is added to the folder. It's giving me two problems. One is that it seems to freeze up when Form2 shows, and the other is that the text of Label1 on Form2 is never equal to anything. I'd appreciate any help with this.
VB.NET:
Public Class Form1
WithEvents fsw As System.IO.FileSystemWatcher
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
Dim x As Integer = 0
For x = 0 To My.Settings.Orders.Count - 1
If My.Settings.Orders(x) = TextBox2.Text Then
TextBox2.Text = My.Settings.messages(x)
End If
Next
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
My.Settings.Orders.Add(TextBox4.Text)
My.Settings.messages.Add(TextBox1.Text)
End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
FolderBrowserDialog1.ShowDialog()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim dm As Integer = My.Settings.Orders.IndexOf(TextBox2.Text)
My.Settings.Orders.RemoveAt(dm)
My.Settings.messages.RemoveAt(dm)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
My.Settings.prooffolder = FolderBrowserDialog1.SelectedPath
Label1.Text = FolderBrowserDialog1.SelectedPath
fsw = New System.IO.FileSystemWatcher(My.Settings.prooffolder, "*.txt")
fsw.NotifyFilter = IO.NotifyFilters.FileName
fsw.EnableRaisingEvents = True
End Sub
Private Sub fsw_Created(ByVal sender As Object, ByVal e As System.IO.FileSystemEventArgs) Handles fsw.Created
Dim filecomp() As String = e.Name.Split("-")
If My.Settings.Orders.IndexOf(filecomp(0)) >= 0 Then
MessageBox.Show(e.Name)
Dim myindex As Integer = My.Settings.Orders.IndexOf(filecomp(0))
My.Settings.message = My.Settings.messages(myindex)
Dim fm2 As Form2
fm2 = New Form2
fm2.TextBox1.Text = My.Settings.message
fm2.Show()
My.Settings.messages.RemoveAt(My.Settings.Orders.IndexOf(filecomp(0)))
My.Settings.Orders.Remove(filecomp(0))
End If
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not My.Settings.prooffolder = "" Then
fsw = New System.IO.FileSystemWatcher(My.Settings.prooffolder, "*.txt")
fsw.NotifyFilter = IO.NotifyFilters.FileName
fsw.EnableRaisingEvents = True
End If
End Sub
End Class