We help IT Professionals succeed at work.

Easy question....updating a text file using streamwriter.

collages asked
Last Modified: 2010-04-23
I have a text file the first 6 lines of which are:

monthnumber1 = 08
daynumber1 = 21
yearnumber1 = 2007
monthnumber2 = 08
daynumber2 = 21
yearnumber2 = 2007

The month, day and year numbers will always be different but they will always be 2, 2 and 4 characters respectively.  These will ALWAYS be the first 6 lines of the text file.

I am working on a VB.Net that will update the values in this text file on a daily basis.  Here is what I have so far:

Dim MonthNumber1 As String = ""
        Dim Daynumber1 As String = ""
        Dim YearNumber1 As String = ""

        Dim MonthNumber2 As String = ""
        Dim Daynumber2 As String = ""
        Dim YearNumber2 As String = ""

        If DatePart(DateInterval.Weekday, Today()) = 2 Then
            MonthNumber1 = DatePart(DateInterval.Month, DateAdd(DateInterval.Day.ToString, -3, Today()))
            Daynumber1 = DatePart(DateInterval.Day, DateAdd(DateInterval.Day, -3, Today()))
            YearNumber1 = DatePart(DateInterval.Year, DateAdd(DateInterval.Day, -3, Today()))

            MonthNumber2 = DatePart(DateInterval.Month, DateAdd(DateInterval.Day.ToString, -2, Today()))
            Daynumber2 = DatePart(DateInterval.Day, DateAdd(DateInterval.Day, -2, Today()))
            YearNumber2 = DatePart(DateInterval.Year, DateAdd(DateInterval.Day, -2, Today()))
            MonthNumber1 = DatePart("M", DateAdd("D", -1, Today()))
            Daynumber1 = DatePart("D", DateAdd("D", -1, Today()))
            YearNumber1 = DatePart(DateInterval.Year, DateAdd("D", -1, Today()))
        End If
        If Len(MonthNumber1) = 1 Then
            MonthNumber1 = "0" + MonthNumber1
        End If
        If Len(Daynumber1) = 1 Then
            Daynumber1 = "0" + Daynumber1
        End If
        If Len(MonthNumber2) = 1 Then
            MonthNumber1 = "0" + MonthNumber1
        End If
        If Len(Daynumber2) = 1 Then
            Daynumber1 = "0" + Daynumber1
        End If

So at this point I will have all of the values set...I just need to update the values in the text file to the ones set from the VB.Net application.

Thanks for your help and let me know if you have any questions.
Watch Question



I understand how to create a text file, and I know how to read from one (using streamreader and textwriter).

I guess what I'm struggling with here is I need to write to a specific part of the file and I;m not sure how to do that.
Top Expert 2007
This one is on us!
(Get your first solution completely free - no credit card required)


Thats exactly what I needed, thanks a lot.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.