Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Visual Basic 2005 Basics
|
Visual Basic 2005 Basics If you are new to Visual Basic programming with version 2005, this is the place to start your questions. For questions about the book: Beginning Visual Basic 2005 by Thearon Willis and Bryan Newsome, ISBN: 0-7645-7401-9 please, use this forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2005 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 25th, 2006, 08:03 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Opening a txt file - can't edit it

This little app works fine, except when the text file opens within the window, I can't type within it or make any changes to the text, other than using the delete key which works normally. Any ideas why this is so? Am I opening it readonly/non-editable somehow?

TIA...

Here is my code:

Code:
Public Class Dialogs

    Private strFileName As String

    Private Sub btnOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
        With OpenFileDialog1
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .Title = "Demo Open File Dialog"
            .FileName = ""
            .InitialDirectory = "C:\"
        End With

        'Show the Open dialog and if the user clicks the Open button,
        'load the file
        If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Dim allText As String
            Try
                'Save the file name
                strFileName = OpenFileDialog1.FileName
                'Read the contents of the file
                allText = My.Computer.FileSystem.ReadAllText(strFileName)
                'Display the file contents in the TextBox
                txtFile.Text = allText
            Catch fileException As Exception
                Throw fileException
            End Try
        End If
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        With SaveFileDialog1
            .DefaultExt = "txt"
            .FileName = strFileName
            .Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*"
            .FilterIndex = 1
            .OverwritePrompt = True
            .Title = "Demo save file dialog"
        End With
        If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            Try
                strFileName = SaveFileDialog1.FileName
                Dim filePath As String

                filePath = System.IO.Path.Combine(My.Computer.FileSystem.SpecialDirectories.MyDocuments, strFileName)
                My.Computer.FileSystem.WriteAllText(filePath, txtFile.Text, False)
            Catch fileException As Exception

            End Try


        End If

    End Sub
End Class
 
Old September 25th, 2006, 08:06 AM
Registered User
 
Join Date: Sep 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Oops, scrub that. Seems to be a problem only with one particular text file. Thanks anyway.






Similar Threads
Thread Thread Starter Forum Replies Last Post
read any ".txt" file RodrigoGuteriez C# 3 November 18th, 2008 01:07 PM
Reading txt file umeshtheone SQL Server 2000 9 May 15th, 2007 12:43 AM
Reading a txt file AlphaX Beginning VB 6 2 February 20th, 2006 11:22 PM
export to .txt file meimy Pro VB.NET 2002/2003 0 May 31st, 2004 02:24 AM





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