Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Continuous file monitoring problem

Continuous file monitoring problem

Scheduled Pinned Locked Moved Visual Basic
helpphphtmldatabasecom
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    arp_059
    wrote on last edited by
    #1

    I am basically an electronics student. I am currently developing a vb code to control multiple devices using bluetooth. I am making use of vb here. I am a very beginner in vb and dont have much knowledge. Please help me with examples. Problem: Below, I have provided the code which I developed for my project. It monitors few text files located in C:\ directory and based on that, the relevant code is sent through parallel port which I use to further purposes. The problem occurred that I need to monitor those files. I used loop, do, if, goto, while statements. Till the end button is pressed, it needs to monitor the existence of files. All the statements resulted in "NOT RESPONDING" state. Can anyone please help me for that. I just want my program to loop continuously from end to beginning till the end button(command2) is pressed. Then I used a check button and used if command, it also did not work. Here is the code I wrote till now ----------------------------------- Private Sub Command1_Click() ' following sections to read file line obtained from http://www.codeguru.com/forum/archive/index.php/t-315872.html Dim strFile As String Dim PortAddress As Integer 'Dim iFile As Integer Dim strContent As String Dim strContent2 As String Dim strContent3 As String Dim strContent4 As String PortAddress = &H378 'TO Do Add code here to put a filename with path in strFile Label1.Caption = "light is off" 'display status Label3.Caption = "fan is off" 'display status file1 = "c:\lighton.txt" file2 = "c:\lightoff.txt" file3 = "c:\fanon.txt" file4 = "c:\fanoff.txt" 'iFile = FreeFile '1=lighton.txt 2=lightoff.txt 3=fanon.txt 4=fanoff.txt 'restart: Do If (Len(Dir$(file1)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lighton.txt" For Input As #1 'The following will read the first line from the file Line Input #1, strContent ' read 1st line in the file Close #1 ' close file If (strContent = "light on") Then 'check validity of file Label1.Caption = "light is on" 'display status Value = Inp(PortAddress) Value = Value Or &HF 'make lsbs high Out PortAddress, Value 'output the value End If For i = 1 To 5 If (Len(Dir$(file2)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lightoff.txt" For Input

    M D 2 Replies Last reply
    0
    • A arp_059

      I am basically an electronics student. I am currently developing a vb code to control multiple devices using bluetooth. I am making use of vb here. I am a very beginner in vb and dont have much knowledge. Please help me with examples. Problem: Below, I have provided the code which I developed for my project. It monitors few text files located in C:\ directory and based on that, the relevant code is sent through parallel port which I use to further purposes. The problem occurred that I need to monitor those files. I used loop, do, if, goto, while statements. Till the end button is pressed, it needs to monitor the existence of files. All the statements resulted in "NOT RESPONDING" state. Can anyone please help me for that. I just want my program to loop continuously from end to beginning till the end button(command2) is pressed. Then I used a check button and used if command, it also did not work. Here is the code I wrote till now ----------------------------------- Private Sub Command1_Click() ' following sections to read file line obtained from http://www.codeguru.com/forum/archive/index.php/t-315872.html Dim strFile As String Dim PortAddress As Integer 'Dim iFile As Integer Dim strContent As String Dim strContent2 As String Dim strContent3 As String Dim strContent4 As String PortAddress = &H378 'TO Do Add code here to put a filename with path in strFile Label1.Caption = "light is off" 'display status Label3.Caption = "fan is off" 'display status file1 = "c:\lighton.txt" file2 = "c:\lightoff.txt" file3 = "c:\fanon.txt" file4 = "c:\fanoff.txt" 'iFile = FreeFile '1=lighton.txt 2=lightoff.txt 3=fanon.txt 4=fanoff.txt 'restart: Do If (Len(Dir$(file1)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lighton.txt" For Input As #1 'The following will read the first line from the file Line Input #1, strContent ' read 1st line in the file Close #1 ' close file If (strContent = "light on") Then 'check validity of file Label1.Caption = "light is on" 'display status Value = Inp(PortAddress) Value = Value Or &HF 'make lsbs high Out PortAddress, Value 'output the value End If For i = 1 To 5 If (Len(Dir$(file2)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lightoff.txt" For Input

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Take a look at the FileWatcher class (I think) this works for small file numbers (chokes when there are too many events. Also you should change your loop to a timer based application, something like Start time Timer tick event Turn timer off Process directory turn timer on Set the tick for 1 second

      1 Reply Last reply
      0
      • A arp_059

        I am basically an electronics student. I am currently developing a vb code to control multiple devices using bluetooth. I am making use of vb here. I am a very beginner in vb and dont have much knowledge. Please help me with examples. Problem: Below, I have provided the code which I developed for my project. It monitors few text files located in C:\ directory and based on that, the relevant code is sent through parallel port which I use to further purposes. The problem occurred that I need to monitor those files. I used loop, do, if, goto, while statements. Till the end button is pressed, it needs to monitor the existence of files. All the statements resulted in "NOT RESPONDING" state. Can anyone please help me for that. I just want my program to loop continuously from end to beginning till the end button(command2) is pressed. Then I used a check button and used if command, it also did not work. Here is the code I wrote till now ----------------------------------- Private Sub Command1_Click() ' following sections to read file line obtained from http://www.codeguru.com/forum/archive/index.php/t-315872.html Dim strFile As String Dim PortAddress As Integer 'Dim iFile As Integer Dim strContent As String Dim strContent2 As String Dim strContent3 As String Dim strContent4 As String PortAddress = &H378 'TO Do Add code here to put a filename with path in strFile Label1.Caption = "light is off" 'display status Label3.Caption = "fan is off" 'display status file1 = "c:\lighton.txt" file2 = "c:\lightoff.txt" file3 = "c:\fanon.txt" file4 = "c:\fanoff.txt" 'iFile = FreeFile '1=lighton.txt 2=lightoff.txt 3=fanon.txt 4=fanoff.txt 'restart: Do If (Len(Dir$(file1)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lighton.txt" For Input As #1 'The following will read the first line from the file Line Input #1, strContent ' read 1st line in the file Close #1 ' close file If (strContent = "light on") Then 'check validity of file Label1.Caption = "light is on" 'display status Value = Inp(PortAddress) Value = Value Or &HF 'make lsbs high Out PortAddress, Value 'output the value End If For i = 1 To 5 If (Len(Dir$(file2)) <> 0) Then 'lighton.txt file existance check For j = 1 To 255 Close #j Next j Open "c:\lightoff.txt" For Input

        D Offline
        D Offline
        Dave Kreskowiak
        wrote on last edited by
        #3

        Wow, this is some old code. Warning - This code will NOT work with VB.NET and won't work at all under a Windows NT Kernel O/S, such as WIndows 2000, XP, 2003, Vista, ... What version of Basic is this and what O/S are you planning on running it under?

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups