473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

[VB.Net] : Read Text File Contents with Regular Intervals

ak1dnar
1,584 Expert 1GB
Hi,

I have created Sub in VB.net application, Which reads a text file contents.

Expand|Select|Wrap|Line Numbers
  1. Sub IPsetter()
  2.         Dim fileName As String
  3.         Dim realIParray As String() = Nothing
  4.         Dim ipString As String
  5.  
  6.  
  7.         fileName = "D:\IPFinder\WWIP\ip.txt"
  8.  
  9.         Try
  10.             Dim stream As StreamReader
  11.             stream = New StreamReader(fileName)
  12.             ipString = stream.ReadToEnd()
  13.             realIParray = ipString.Split(":")
  14.             Dim realIP As String = realIParray(1).ToString
  15.             SetNewIP(realIP)
  16.         Catch exceptionCatch As IOException
  17.             lbl_ip.Text = "Error Detected"
  18.         End Try
  19.     End Sub
  20.  
This Sub is calling from this;

Expand|Select|Wrap|Line Numbers
  1.  Private Sub IPFinder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  2.         IPsetter()
  3.     End Sub
The text file content(a IP address) will change time to time. So when there is a update on the text file I need to update the lbl_ip .Text property also.

Example:

When I execute the Form for the first time IP address will read from the text file and Display it in the lbl_ip. Here after, I am not going to close this form. while the form is running the text file contents might updating. so when its updating I need display the same value in Label.

My Idea is to call for IPFinder_Load Sub with Intervals, No Idea about doing such a thing. Any Suggestions?

Thanks!
Aug 6 '07 #1
6 2901
TRScheel
638 Expert 512MB
Why not use a FileSystemWatcher?

Edit:
MSDN Information on FileSystemWatcher
Aug 6 '07 #2
ak1dnar
1,584 Expert 1GB
Why not use a FileSystemWatcher?

Edit:
MSDN Information on FileSystemWatcher
Yeap Its a good point.
My idea is, If there is changes on the text file read the text file, So no need to keep on execute the application with intervals. Its waisting memory though it a simple App.

I'll take a look at to the link, but I am not really a not VB.Net coder. At least I'll be trying..

Thanks a Lot.
Aug 7 '07 #3
ak1dnar
1,584 Expert 1GB
Hi,
I tried FileSystemWatcher and there are few issues that I couldn't fix.

  • When I execute the Application for the first time Its reading the text file and updates the lable.
  • Then I opened the text file and changed the value, Now also Lable control get updated
  • But When I am trying it several times this error is getting



Expand|Select|Wrap|Line Numbers
  1.  Dim fsw As FileSystemWatcher
  2.     Private Sub IPFinder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  3.         IPsetter()
  4.     End Sub
  5.  
  6.     Sub IPsetter()
  7.         Dim fileName As String
  8.         Dim realIParray As String() = Nothing
  9.         Dim ipString As String
  10.  
  11.  
  12.         fileName = "D:\IPFinder\WWIP\ip.txt"
  13.  
  14.         Try
  15.             Dim stream As StreamReader
  16.             stream = New StreamReader(fileName)
  17.             ipString = stream.ReadToEnd()
  18.             realIParray = ipString.Split(":")
  19.             Dim realIP As String = realIParray(1).ToString
  20.             SetNewIP(realIP)
  21.             stream.Close()
  22.             KeepWatching()
  23.         Catch exceptionCatch As IOException
  24.             lbl_ip.Text = "Error Detected"
  25.         End Try
  26.     End Sub
  27.     Sub SetNewIP(ByVal realIP)
  28.         lbl_ip.Text = realIP
  29.     End Sub
  30.     Sub KeepWatching()
  31.         fsw = New FileSystemWatcher
  32.         fsw.Path = "D:\IPFinder\WWIP"
  33.         fsw.Filter = "ip.txt"
  34.         Try
  35.             fsw.EnableRaisingEvents = True
  36.             AddHandler fsw.Changed, AddressOf OnChanged
  37.         Catch ex As Exception
  38.             MessageBox.Show(ex.ToString)
  39.         Finally
  40.  
  41.         End Try
  42.  
  43.     End Sub
  44.     Private Sub OnChanged(ByVal source As Object, ByVal e As FileSystemEventArgs)
  45.         IPsetter()
  46.     End Sub
  47.  
Text File :


Expand|Select|Wrap|Line Numbers
  1. ip:156.43.248.556
Aug 7 '07 #4
ak1dnar
1,584 Expert 1GB
Bumping... back to the top please help !
Aug 9 '07 #5
Create an exe and use the window scheduler to specify the schedule.
Start->Programs->Accessories->Sytem Tools->Scheduled Tasks
Aug 9 '07 #6
ak1dnar
1,584 Expert 1GB
Create an exe and use the window scheduler to specify the schedule.
Start->Programs->Accessories->Sytem Tools->Scheduled Tasks
Cool ! Thanks for the stuffs. But I do like to build up my own things always.
have a nice Time!
Thanks & Regards!
-ajaxrand
Aug 9 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: john | last post by:
Here is the short story of what i'm trying to do. I have a 4 sided case labeling printer setting out on one of our production lines. Now then i have a vb.net application that sends data to this...
2
by: Phil Latio | last post by:
We have despatch process which kicks out picking information into text files at hourly intervals. The text files are named sequentially by process; 'ABC.txt', 'ABC01.txt', 'ABC02.txt' for one...
4
by: Pete | last post by:
I'd like to add a basic chat application to my web site to get the members talking more, I've decided to limit the number of users to 30. There will be a seperate popup with a frame & three pages...
0
by: Anonieko Ramos | last post by:
Answer. Use IHttpHandler. thanks Ro ry for coming up with this code. It processes css file to add variables. neat idea using System; using System.IO; using System.Text; using...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
3
by: Peter Strøiman | last post by:
Hi. I have a web application that needs to run tasks at regular intervals. E.g. it must send out emails every night to people who subscribe to that service. I have come up with one solution,...
0
by: shamirza | last post by:
· When was .NET announced? Bill Gates delivered a keynote at Forum 2000, held June 22, 2000, outlining the .NET 'vision'. The July 2000 PDC had a number of sessions on .NET technology, and...
0
by: shamirza | last post by:
· What is view state and use of it? The current property settings of an ASP.NET page and those of any ASP.NET server controls contained within the page. ASP.NET can detect when a form is requested...
1
by: cnixuser | last post by:
Hello, I am having a problem that I believe is related to the way a stream reader object looks for a text file by default. What I am doing is using a StreamReader object to read the text of a text...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.