[2008] OpenFileDialog Help!
NOTE: The All words are no loner caps is not my problem that was off topic!
Ok I have Made A HEX Editor But It Has A Few Things That I dont Want Or Need To Be Fixed And I Need Your Guys Help.
1. So for first i have made a OpenFileDialog right so when clicked it askes to load a file well I have made it so it translates normal text format to HEX format well but for some reason it creates a backup once i load a file is there any way to remove that so it doesnt create a backup? Here is my code!
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
OpenFileDialog.Filter = "All Files (*)|*|All Files (*.*)|*.*"
If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
Dim FileName As String = OpenFileDialog.FileName
Dim sw As New IO.StreamWriter("Backup!")
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 StringBuilder()
For Each singleByte As Byte In b
sb.AppendFormat("{0:x2}", singleByte)
Next
TextBox1.Text = sb.ToString()
sw.Write(TextBox1.Text)
sw.Close()
MsgBox("File Loaded!")
End If
End Sub
2. I can't seem to figure out the code ok now what I am trying to do is make A SaveFileDialog that when clicked it askes to save the text in my textbox but when i save it saves in HEX format is there a code to translate HEX back to normal text format? I found a code here on this site with some other users help and thanks but this is the opposite code than i need what this code does is translate normal format to HEX but i want it to translate HEX to normal format! Here is my code!
Code:
Dim aryText As String
Dim FILE_NAME As String
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
FILE_NAME = SaveFileDialog1.FileName
aryText = Textbox1.Text
Dim byt() As String = Array.ConvertAll(aryText.ToCharArray, New Converter(Of Char, String)(Function(X) Microsoft.VisualBasic.Asc(X).ToString("X")))
Using objWriter As New System.IO.StreamWriter(FILE_NAME)
Array.ForEach(byt, AddressOf objWriter.Write)
End Using
End If__________________
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
1. Answer to your first question.
vb.net Code:
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs _
) Handles Button1.Click
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
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(fileName)
Dim encoding As New System.Text.ASCIIEncoding()
Dim b As Byte() = encoding.GetBytes(s)
Dim sb As New StringBuilder()
For Each singleByte As Byte In b
sb.AppendFormat("{0:x2}", singleByte)
Next
TextBox1.Text = sb.ToString()
MsgBox("File Loaded!")
End If
End Sub
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Quote:
Originally Posted by Deepak Sakpal
1. Answer to your first question.
vb.net Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim OpenFileDialog As New OpenFileDialog
OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
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 StringBuilder()
For Each singleByte As Byte In b
sb.AppendFormat("{0:x2}", singleByte)
Next
TextBox1.Text = sb.ToString()
MsgBox("File Loaded!")
End If
End Sub
Thanks for the time to write this up +REP for you!:) Now I just only need a Answer for question 2!
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Try this code for your second answer:
vb.net Code:
Dim FILE_NAME As String
If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
FILE_NAME = SaveFileDialog1.FileName
Dim a As String = Textbox1.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
MessageBox.Show(b)
Dim objWriter As System.IO.StreamWriter
objWriter = New System.IO.StreamWriter(FILE_NAME)
objWriter.Write(b)
objWriter.Close()
End If
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Ok Now I have One Problem!
Everything Works But Some Of It Comes Up As Question Marks But Only For Weird Characters Like Ð å § And So On!?! Any Way To Fix That!
Re: [2008] OpenFileDialog (No Longer Caps In Post!)
Its Kinda Like It Reads It But When It Saves It And I Open It Up in A Different HEX Editor It Shows Those Characters As Question Marks!