Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help! embeded text fle in a form

Posted on 2004-09-02
4
Medium Priority
?
240 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
ID: 11961856
how are you reading and writing the text, with a streamreader  and writer ?
0
 

Author Comment

by:mpaver
ID: 11961962
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
ID: 11961975
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 600 total points
ID: 11962235
Hi Mpayer,

just change this

           FileOpen(nr, FileName, OpenMode.Append)

to this

           FileOpen(nr, FileName, OpenMode.output)

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Integration Management Part 2
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

972 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