0

I have the following code that simply opens up a folder with txt files.

Private Sub OpenTabpageTextFolderToolStripMenuItem_Click( _
            ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles OpenTabpageTextFolderToolStripMenuItem.Click
  Dim OpenFolder = (RootDrive & "QuickEmailer2\TabTxt")
  Process.Start("explorer.exe", OpenFolder)
End Sub

The user then edits a txt file, and closes. I would like to call my refresh code and make use of the changes to the txt file, but if I put the call after process.start, it runs without waiting?

I could use code to do these edit, but there are 80 files to choose from and they only need edit them once (or twice) when setting up the program for the first time.

I am sure a bit of code that says:

Private Sub OpenTabpageTextFolderToolStripMenuItem_Click( _
            ByVal sender As System.Object, ByVal e As System.EventArgs) _
            Handles OpenTabpageTextFolderToolStripMenuItem.Click
  Dim OpenFolder = (RootDrive & "QuickEmailer2\TabTxt")
  Process.Start("explorer.exe", OpenFolder)
  '**I will hang on here while you do your stuff, then I will continue...**
  Call RefreshfromAllTxtFiles()
End Sub
Victor Zakharov
  • 25,801
  • 18
  • 85
  • 151

2 Answers2

2

alternative solution: use 2 buttons/steps to setting up the program for the first time!

  1. button/step #1: open setup files
  2. button/step #2: setup files modified... PROCEED!
tezzo
  • 10,858
  • 1
  • 25
  • 48
  • 1
    I don't think using a FileSystemWatcher is a good idea! Uncle Wiggy said there are 80 files in this folder: it's not possible to _automatically_ determine when a user has completed the editing of all the interested file! – tezzo May 23 '13 at 15:47
  • Yes I agree with you. There is this requirement to wait for the editing end that render the FileSystemWatcher ineffective. Perhaps yours is the only answer possibile. Probably you could add a MessageBox to stop the setup program until the user ends the editing – Steve May 23 '13 at 16:04
  • I read this as they are choosing 1 of 80 files to edit. The code below wouldn't fire until the text file was saved, but agree that FSW isn't the way to do this if they are modifying all 80. – maxedev May 23 '13 at 16:07
1

Along the lines of Steve's comment, you can use a FileSystemWatcher to monitor changes to the directory. Something like this can get you started:

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    Dim fsw As FileSystemWatcher
    fsw = New System.IO.FileSystemWatcher()

    'this is the folder we want to monitor
    fsw.Path = "c:\temp"
    fsw.NotifyFilter = IO.NotifyFilters.Attributes

    AddHandler fsw.Changed, AddressOf IveBeenChanged
    fsw.EnableRaisingEvents = True
End Sub
Private Sub IveBeenChanged(ByVal source As Object, ByVal e As System.IO.FileSystemEventArgs)
    If e.ChangeType = IO.WatcherChangeTypes.Changed Then
        'this displays the file that changed after it is saved
        MessageBox.Show("File " & e.FullPath & " has been modified")

        ' you can call RefreshfromAllTxtFiles() here
    End If
End Sub
maxedev
  • 941
  • 8
  • 18
  • Maxedev, Thanks.. and ? If I leave it as a messagebox, I get the message File has been modified, twice? If I remove the message and call my RefreshTxtfiles() it just closes the program? I am running it in debug, not compiled, but don't see why it either messages me twice or closes? – Uncle Wiggy May 23 '13 at 16:59
  • OK I had a brainwave..! and it came about as a direct result from your help...The Simple answer ! Process.Start("explorer.exe", OpenFolder) MsgBox("Press OK, AFTER you have finished editing and closing the TabTxt folder", MsgBoxStyle.OkCancel) GetTabText() End Sub – Uncle Wiggy May 23 '13 at 17:11
  • Up pops a msgbox, that sits and waits for input before continuing, and will do my reset when OK is pressed ! Thanks for the bread crumbs of thought trails ! I cannot praise the help you give so freely to all who asks.. Barry aka Uncle Wiggy – Uncle Wiggy May 23 '13 at 17:11