Solved

Help! embeded text fle in a form

Posted on 2004-09-02
4
225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 total points
ID: 11962235
Hi Mpayer,

just change this

           FileOpen(nr, FileName, OpenMode.Append)

to this

           FileOpen(nr, FileName, OpenMode.output)

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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