Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[VB.NET] Saving words into a text document.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
I'm C.H.
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Dec 2006
Posts: 1000
Location: Sweden

PostPosted: Fri May 29, 2009 11:43 am    Post subject: [VB.NET] Saving words into a text document. Reply with quote

Yeah. I want to know how to make VB.net save the words you type from a textbox into a .txt document (and create a .txt file if it doesn't exist) in the same place as the program.
_________________
Omg. I need something to do...

*-* My Flash Trainers *-*

*-* My Mouse Vac Tut *-*

Back to top
View user's profile Send private message
Scathe
I post too much
Reputation: 0

Joined: 02 Aug 2006
Posts: 3631
Location: Smoking a blunt

PostPosted: Fri May 29, 2009 11:52 am    Post subject: Reply with quote

http://www.freevbcode.com/ShowCode.Asp?ID=4492
_________________

<Moose> they will call me beard penis
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
shhac
Expert Cheater
Reputation: 0

Joined: 30 Oct 2007
Posts: 108

PostPosted: Fri May 29, 2009 12:48 pm    Post subject: Reply with quote

Use it like
Code:
Dim xyz As New ReadWriteFile
xyz.WriteTxtFile("C:\textfile.txt","Hello World!")


Code:
'By Shhac
Public Class ReadWriteFile
    Public FileContents As String = vbNullString, _
           ErrorMessage As String = vbNullString
    Private relPath As String = Application.StartupPath & "\"

    Public Function clear() As Boolean
        FileContents = vbNullString
        ErrorMessage = vbNullString
        Return True
    End Function

    Public Function CheckFileExists(ByVal Path As String) As Boolean
        Return System.IO.File.Exists(Path)
    End Function

    Public Function CheckRelFileExists(ByVal RelativePath As String) As Boolean
        Return CheckFileExists(relPath & RelativePath)
    End Function

    Public Function CheckDirectoryExists(ByVal Path As String) As Boolean
        Return System.IO.Directory.Exists(Path)
    End Function

    Public Function CheckRelDirectoryExists(ByVal RelativePath As String) As Boolean
        Return CheckDirectoryExists(relPath & RelativePath)
    End Function

    Public Function CreateFile(ByVal Path As String, Optional ByVal Overwrite As Boolean = False) As Boolean
        If Overwrite = False Then
            If CheckFileExists(Path) Then
                Return False
            Else
                Try
                    Dim File As System.IO.FileStream
                    File = System.IO.File.Create(Path)
                    File.Close()
                    Return CheckFileExists(Path)
                Catch Ex As Exception
                    ErrorMessage = Ex.Message
                    Return False
                End Try
            End If
        Else
            Try
                Dim File As System.IO.FileStream
                File = System.IO.File.Create(Path)
                File.Close()
                Return CheckFileExists(Path)
            Catch Ex As Exception
                ErrorMessage = Ex.Message
                Return False
            End Try
        End If
    End Function

    Public Function CreateRelFile(ByVal RelativePath As String) As Boolean
        Return CreateFile(relPath & RelativePath)
    End Function

    Public Function CreateDirectory(ByVal Path As String) As Boolean
        Try
            System.IO.Directory.CreateDirectory(Path)
            Return CheckDirectoryExists(Path)
        Catch Ex As Exception
            ErrorMessage = Ex.Message
            Return False
        End Try
    End Function

    Public Function CreateRelDirectory(ByVal RelativePath As String) As Boolean
        Return CreateDirectory(relPath & RelativePath)
    End Function

    Public Function ReadTxtFile(ByVal Path As String, Optional ByVal Encoding As String = "Unicode", Optional ByVal detectEncoding As Boolean = True) As Boolean
        If Not CheckFileExists(Path) Then
            Return False
        Else
            Dim objReader As System.IO.StreamReader
            Try
                objReader = New System.IO.StreamReader(Path, System.Text.Encoding.GetEncoding(Encoding), detectEncoding)
                FileContents = objReader.ReadToEnd()
                objReader.Close()
                objReader = Nothing
                Return True
            Catch Ex As Exception
                ErrorMessage = Ex.Message
                Return False
            End Try
        End If
    End Function

    Public Function WriteTxtFile(ByVal Path As String, ByVal strData As String, Optional ByVal Append As Boolean = True, Optional ByVal Encoding As String = "Unicode", Optional ByVal ForceWrite As Boolean = False) As Boolean
        If Not CheckFileExists(Path) Then
            If ForceWrite Then
                If CreateFile(Path) Then
                    Return WriteTxtFile(Path, strData, Append, Encoding, ForceWrite)
                Else
                    Return False
                End If
            Else
                Return False
            End If
        Else
            Dim objWriter As System.IO.StreamWriter
            Try
                objWriter = New System.IO.StreamWriter(Path, Append, System.Text.Encoding.GetEncoding(Encoding))
                objWriter.Write(strData)
                objWriter.Close()
                objWriter = Nothing
                Return True
            Catch Ex As Exception
                ErrorMessage = Ex.Message
                Return False
            End Try
        End If
    End Function

    Public Function ReadRelTxtFile(ByVal RelativePath As String, Optional ByVal Encoding As String = "Unicode", Optional ByVal detectEncoding As Boolean = True) As Boolean
        Return ReadTxtFile(relPath & RelativePath, Encoding, detectEncoding)
    End Function

    Public Function WriteRelTxtFile(ByVal RelativePath As String, ByVal strData As String, Optional ByVal Append As Boolean = True, Optional ByVal Encoding As String = "Unicode", Optional ByVal ForceWrite As Boolean = False) As Boolean
        Return WriteTxtFile(relPath & RelativePath, strData, Append, Encoding, ForceWrite)
    End Function

    Public Function DeleteFile(ByVal Path As String) As Boolean
        Try
            System.IO.File.Delete(Path)
            Return Not CheckFileExists(Path)
        Catch Ex As Exception
            Return False
        End Try
    End Function

    Public Function DeleteRelFile(ByVal RelativePath As String) As Boolean
        Return DeleteFile(relPath & RelativePath)
    End Function

    Public Function DeleteDirectory(ByVal Path As String, Optional ByVal Recursive As Boolean = True) As Boolean
        Try
            System.IO.Directory.Delete(Path, Recursive)
            Return Not CheckDirectoryExists(Path)
        Catch Ex As Exception
            Return False
        End Try
    End Function

    Public Function DeleteRelDirectory(ByVal RelativePath As String) As Boolean
        Return DeleteDirectory(relPath & RelativePath)
    End Function
End Class
Back to top
View user's profile Send private message
yoyonerd
Grandmaster Cheater
Reputation: 0

Joined: 26 Apr 2008
Posts: 699
Location: -->formerly yoyonerd<--

PostPosted: Sat May 30, 2009 2:52 pm    Post subject: Reply with quote

Use a richtextbox, it has a built in method to save the text in itself.

I think its SaveFile().

_________________
Back to top
View user's profile Send private message AIM Address
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat May 30, 2009 3:47 pm    Post subject: Reply with quote

http://msdn.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx

their example writes a text file, then reads it.
Back to top
View user's profile Send private message
NINTENDO
Grandmaster Cheater Supreme
Reputation: 0

Joined: 02 Nov 2007
Posts: 1371

PostPosted: Sat May 30, 2009 6:08 pm    Post subject: Reply with quote

slovach wrote:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.readtoend.aspx

their example writes a text file, then reads it.

I also like streamreaders/writers. Why make 1000 pages long classes for it.. It's like reinventing the wheel.

_________________
Intel over amd yes.
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
iTz SWAT
I post too much
Reputation: 1

Joined: 20 Dec 2007
Posts: 2227
Location: Me.Location;

PostPosted: Sat May 30, 2009 7:18 pm    Post subject: Reply with quote

It also depends, do you want the program to save the file to a set location without user control of destination, then you use:
Code:
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim TargetFile As StreamWriter
        Try
            TargetFile = New StreamWriter("C:\test.txt", True)
        Catch
            MessageBox.Show("Error opening " & "test.txt")
        End Try
        Try
            TargetFile.Write(TextBox1.Text)
        Catch
            MessageBox.Show("Error writing file")
        End Try
        TargetFile.Close()
        MessageBox.Show("Text saved to " & "test.txt")
    End Sub

If you would like a Save Dialog Box then:
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim saveFileDialog1 As System.Windows.Forms.SaveFileDialog
        saveFileDialog1 = New System.Windows.Forms.SaveFileDialog()
        SaveFileDialog1.CreatePrompt = True
        saveFileDialog1.FileName = "text1"
        SaveFileDialog1.Filter = "Word (*.doc) |*.doc;*.rtf|(*.txt) |*.txt|(*.*) |*.*"
        If SaveFileDialog1.ShowDialog() = DialogResult.OK Then
            Console.WriteLine(SaveFileDialog1.FileName)
        End If
    End Sub


Personally I'd prefer to have the option to save where I want in a nice SaveFileDialog...
I'd choose the 2nd one...

_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites