Solved

Help! embeded text fle in a form

Posted on 2004-09-02
4
216 Views
Last Modified: 2010-04-23
Hi, I've managed to embed a text file into a textbox on a form when i click a button, but I'm trying to get it so I can edit the text document in the textbox and then click a button to save it. I've managed to make it save but it always saves the new information plus the old information in the text file. Is there a way to erase everything in the text document and then save the new information on top?

Thanks

mpaver
0
Comment
Question by:mpaver
  • 2
  • 2
4 Comments
 
LVL 25

Expert Comment

by:RonaldBiemans
Comment Utility
how are you reading and writing the text, with a streamreader  and writer ?
0
 

Author Comment

by:mpaver
Comment Utility
sorry, it's a stremreader, but I will change if you solution works. The thing is, I'm using the same code for saveing the file as I use for registering a new user, it reads the users text file for exisitng lines and enters the saved user on the next line. I need it to do something similar to this, but instead delete it all and then save. The code for the save function is;

-------------------------------------------------------------------------------

        Dim nr As Integer = FreeFile()
        Dim FileName As String
        Dim n As Integer
        Dim gettext As String
        Dim text() As String
        Dim enter As Boolean = False

        'Opening file
        FileName = "\\shelborn\Database\MIS\users.reg"
        FileOpen(nr, Filename, OpenMode.Input)  'Open file for output.


            Do While Not EOF(nr)
                'get those users!!
                gettext = LineInput(nr)
                text = gettext.Split(",")
                For n = 0 To text.Length - 1
                    text(n) = text(n).Trim("""")
                Next
            Try
                If text(0) = txtUsers.Text Then
                    enter = True
                    Exit Do
                End If
            Catch ex As Exception
                'try-catch-statement if line has no more than one argument... (just in case)
            End Try
        Loop

        'Close file
        FileClose(nr)

        If enter = False Then
            accepted = True

            'Opening file
            FileName = "\\shelborn\Database\MIS\users.reg"
            FileOpen(nr, FileName, OpenMode.Append)

            'Write all settings to file
            WriteLine(nr, txtUsers.Text) 'Checkbox1

            'Close file
            FileClose(nr)

        ElseIf enter = True Then
            MsgBox("User already exists!")
        End If

----------------------------------------------------------------------------

The code for the text box stremreader is;

-------------------------------------------------------------------------------

        Dim users As StreamReader

        users = New StreamReader("\\Shelborn\Database\MIS\users.reg")
        txtUsers.Text = users.ReadToEnd
        users.Close()
        txtUsers.Select(0, 0)

-----------------------------------------------------------------------------------

I have 3 buttons;

- one which opens the text file in notepad,
- one which opens the text file in the textbox (the streamreader),
- and one that is meant to save the file.

I'm also hoping in the future to add a search facility.

Thanks

Matthew Paver
0
 

Author Comment

by:mpaver
Comment Utility
forgot to mention the button and text box names;

- save button is btnSave (Duh!)
- button that shows text in textbox is btnChange
- show text file in notepad button is btnShow
- the textbox name is txtUsers

Thanks

matthew paver
0
 
LVL 25

Accepted Solution

by:
RonaldBiemans earned 200 total points
Comment Utility
Hi Mpayer,

just change this

           FileOpen(nr, FileName, OpenMode.Append)

to this

           FileOpen(nr, FileName, OpenMode.output)

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Convert string to date 3 39
Crystal Report for VS2013 17 36
Converting C# Objects into JSON file 7 36
Hide Tab Page 3 18
This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now