Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Help! embeded text fle in a form

Posted on 2004-09-02
4
Medium Priority
?
236 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 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

670 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