Results 1 to 8 of 8

Thread: [2008] OpenFileDialog Help!

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    [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__________________
    Last edited by VB6Learner; Jul 23rd, 2008 at 11:32 PM. Reason: All words were capital!

  2. #2
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008] OpenFileDialog (No Longer Caps In Post!)

    1. Answer to your first question.

    vb.net Code:
    1. Private Sub Button1_Click( _
    2.     ByVal sender As System.Object, _
    3.     ByVal e As System.EventArgs _
    4. ) Handles Button1.Click
    5.    
    6.     Dim OpenFileDialog As New OpenFileDialog
    7.    
    8.     OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
    9.     OpenFileDialog.Filter = "All Files (*)|*|All Files (*.*)|*.*"
    10.    
    11.     If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
    12.         Dim fileName As String = OpenFileDialog.FileName
    13.         Dim s As String = System.IO.File.ReadAllText(fileName)
    14.         Dim encoding As New System.Text.ASCIIEncoding()
    15.         Dim b As Byte() = encoding.GetBytes(s)
    16.         Dim sb As New StringBuilder()
    17.  
    18.         For Each singleByte As Byte In b
    19.             sb.AppendFormat("{0:x2}", singleByte)
    20.         Next
    21.         TextBox1.Text = sb.ToString()
    22.  
    23.         MsgBox("File Loaded!")
    24.     End If
    25. End Sub

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    Re: [2008] OpenFileDialog (No Longer Caps In Post!)

    Quote Originally Posted by Deepak Sakpal
    1. Answer to your first question.

    vb.net Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Dim OpenFileDialog As New OpenFileDialog
    3.         OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
    4.         OpenFileDialog.Filter = "All Files (*)|*|All Files (*.*)|*.*"
    5.         If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
    6.             Dim FileName As String = OpenFileDialog.FileName
    7.             Dim s As String = System.IO.File.ReadAllText(OpenFileDialog.FileName)
    8.             Dim encoding As New System.Text.ASCIIEncoding()
    9.             Dim b As Byte() = encoding.GetBytes(s)
    10.             Dim sb As New StringBuilder()
    11.  
    12.             For Each singleByte As Byte In b
    13.                 sb.AppendFormat("{0:x2}", singleByte)
    14.             Next
    15.             TextBox1.Text = sb.ToString()
    16.  
    17.             MsgBox("File Loaded!")
    18.         End If
    19. End Sub
    Thanks for the time to write this up +REP for you! Now I just only need a Answer for question 2!

  4. #4
    PowerPoster Deepak Sakpal's Avatar
    Join Date
    Mar 2002
    Location
    Mumbai, India
    Posts
    2,424

    Re: [2008] OpenFileDialog (No Longer Caps In Post!)

    Try this code for your second answer:

    vb.net Code:
    1. Dim FILE_NAME As String
    2. If SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
    3.     FILE_NAME = SaveFileDialog1.FileName
    4.     Dim a As String = Textbox1.Text
    5.     Dim b As String = ""
    6.     Dim i As Integer
    7.  
    8.     For i = 0 To a.Length - 2 Step 2
    9.         b = b & Chr(CInt("&H" & a.Substring(i, 2)))
    10.     Next
    11.     MessageBox.Show(b)
    12.  
    13.     Dim objWriter As System.IO.StreamWriter
    14.     objWriter = New System.IO.StreamWriter(FILE_NAME)
    15.     objWriter.Write(b)
    16.     objWriter.Close()
    17. End If

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    Re: [2008] OpenFileDialog (No Longer Caps In Post!)

    Thanks! Wow Your Fast!

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    Re: [2008] OpenFileDialog (No Longer Caps In Post!)

    Thanks! Wow Your Fast!

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    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!

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2008
    Posts
    493

    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width