chrrox
12-25-2008, 05:41 PM
I have got my program to lead the file into the rich text box and I can also paste a short amount of values into it and save the file and it works as expected. But If I click load and then edit a larger file my program hangs when I go to save. Is there a better way to do this code?
Public Class HeaderChange
Public Shared Function ReadAllBytes( _
ByVal path As String _
) As Byte()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog As New Windows.Forms.OpenFileDialog
OpenFileDialog.Filter = "All Files (*)|*|All Files (*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
Dim s As String = System.IO.File.ReadAllText(OpenFileDialog.FileName)
Dim encoding As New System.Text.ASCIIEncoding()
Dim b As Byte() = encoding.GetBytes(s)
Dim sb As New System.Text.StringBuilder()
For Each singleByte As Byte In b
sb.AppendFormat("{0:x2}", singleByte)
Next
RichTextBox1.Text = sb.ToString()
MsgBox("File Loaded!")
End If
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FILE_NAME As String
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
FILE_NAME = SaveFileDialog1.FileName
Dim a As String = RichTextBox1.Text
Dim b As String = ""
Dim i As Integer
For i = 0 To a.Length - 2 Step 2
b = b & Chr(CInt("&H" & a.Substring(i, 2)))
Next
Dim objWriter As System.IO.StreamWriter
objWriter = New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(b)
objWriter.Close()
End If
End Sub
Private Sub HeaderChange_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class
thanks in advance :)
Public Class HeaderChange
Public Shared Function ReadAllBytes( _
ByVal path As String _
) As Byte()
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog As New Windows.Forms.OpenFileDialog
OpenFileDialog.Filter = "All Files (*)|*|All Files (*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
Dim s As String = System.IO.File.ReadAllText(OpenFileDialog.FileName)
Dim encoding As New System.Text.ASCIIEncoding()
Dim b As Byte() = encoding.GetBytes(s)
Dim sb As New System.Text.StringBuilder()
For Each singleByte As Byte In b
sb.AppendFormat("{0:x2}", singleByte)
Next
RichTextBox1.Text = sb.ToString()
MsgBox("File Loaded!")
End If
End Sub
Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim FILE_NAME As String
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
FILE_NAME = SaveFileDialog1.FileName
Dim a As String = RichTextBox1.Text
Dim b As String = ""
Dim i As Integer
For i = 0 To a.Length - 2 Step 2
b = b & Chr(CInt("&H" & a.Substring(i, 2)))
Next
Dim objWriter As System.IO.StreamWriter
objWriter = New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(b)
objWriter.Close()
End If
End Sub
Private Sub HeaderChange_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
End Sub
End Class
thanks in advance :)