troubleshooting Question

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

Avatar of collages
collagesFlag for United States of America asked on
Visual Basic.NET
4 Comments1 Solution226 ViewsLast Modified:
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()))
        Else
            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.
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros