Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 1st, 2005, 05:46 PM
mh mh is offline
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 66
Thanks: 0
Thanked 0 Times in 0 Posts
Default Editing a Text File

Hi,

I'm trying to change the date in a text file to 14 days later once a button is clicked. The following is my code. It does not seem to do anything at all. Can someone please tell me what is going on? Thank you very much.

Imports System
Imports System.IO
Public Class WebForm1
    Inherits System.Web.UI.Page


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            Dim Days As Double
            Dim IntervalType As DateInterval
            Dim SecondDate As Date
            IntervalType = DateInterval.Day
            Days = 14
            ' Create an instance of StreamReader to read from a file.
            Dim sr As StreamReader = New StreamReader("C:\Inetpub\wwwroot\CPS3\FIDELITY0921 2005.txt")
            Dim sw As StreamWriter = New StreamWriter("C:\Inetpub\wwwroot\CPS3\FIDELITY0921 2005.txt")
            Dim line, dt, newdate As String
            Dim i As Integer
            line = sr.ReadLine()
            'Console.WriteLine(line)
            line = sr.ReadLine()
            ' Add some text to the file.
            sr.BaseStream.Seek(65, 71)
            For i = 0 To 6
                dt = sr.Read.ToString
                If i = 0 Then
                    SecondDate = dt
                Else
                    SecondDate = SecondDate & dt
                End If
            Next
            newdate = DateAdd(IntervalType, Days, CDate(SecondDate))
            sw.BaseStream.Seek(65, 71)
            sw.Write(newdate)
            sw.Close()
        Catch
            ' Let the user know what went wrong.
            Console.WriteLine("The file could not be read:")
        End Try
    End Sub
End Class


Reply With Quote
  #2 (permalink)  
Old December 8th, 2005, 02:37 AM
Friend of Wrox
 
Join Date: Feb 2004
Location: Bangalore, Karnataka, India.
Posts: 177
Thanks: 0
Thanked 0 Times in 0 Posts
Default

When you open a file with StreamWriter mode its basically for file writing so if there is a file with that name it deletes the contents in it.

So what you need to do is use StreamWriter with a different file name say "FIDELITY09212005_bak.txt" and then at the end rename the file to "FIDELITY09212005.txt".


It is not how much we do,
but how much love we put in the doing.

-Mother Theresa
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Text When Editing Datagrid elygp ASP.NET 1.0 and 1.1 Professional 1 May 29th, 2007 04:58 PM
Editing text in a richtextbox ja8261 VB.NET 2002/2003 Basics 5 March 9th, 2005 04:10 PM
Terrible Editing, Broken Examples, Rotten text treycarroll Wrox Book Feedback 26 October 31st, 2004 07:44 PM
.NET Text / HTML editing problem clickco General .NET 3 May 12th, 2004 02:47 PM
text boxes / data grids/ editing and paging Barb Lehman Classic ASP Basics 0 December 4th, 2003 12:55 PM



All times are GMT -4. The time now is 08:32 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.