Solved

Help! embeded text fle in a form

Posted on 2004-09-02
4
221 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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

810 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