Read Hex?{Help}

Discussion in 'Programming & Scripting' started by ChitySnipa, Jan 21, 2009 with 10 replies and 343 views.

  1. ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    I have a text box and an openfiledialog, when the user opens a file how can i make the textbox show all the hex codes from the opened file?

     
  2. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Try this
    Code:
    Function StringToHex(ByVal text As String) As String
    Dim hex As String
    For i As Integer = 0 To text.Length - 1
    hex &= Asc(text.Substring(i, 1)).ToString("x").ToUpper
    Next
    Return hex
    End Function
    Then on your button try something like
    Code:
     OpenFileDialog1.ShowDialog()
    
    
    If OpenFileDialog1.ShowDialog = Windows.Forms.DialogResult.Cancel Then
    TextBox1.Text = TextBox1.Text
    Else
    TextBox1.Text = StringToHex(System.IO.File.ReadAllText(OpenFileDialog1.FileName))
    End If
     
    • Like Like x 2
  3. OP
    ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    Thanks so much, please read my other topic and try to help me if you can.
    :biggrin::biggrin::biggrin:
     
  4. sgt frankieboy

    sgt frankieboy Enthusiast

    Messages:
    724
    Ratings:
    133
  5. dschu012

    dschu012 Enthusiast

    Messages:
    760
    Ratings:
    381
    Assuming what he posted was correct then it should work with any file, assuming the file isn't too big causing the program to crash or not respond.
     
    • Like Like x 1
  6. sgt frankieboy

    sgt frankieboy Enthusiast

    Messages:
    724
    Ratings:
    133
    ok thanks:thumbup:
     
  7. classy blackman

    classy blackman Enthusiast

    Messages:
    315
    Ratings:
    21
  8. OP
    ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    Hey how would you save it?
     
  9. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    What do you want to save?
     
  10. OP
    ChitySnipa

    ChitySnipa Banned

    Messages:
    255
    Ratings:
    53
    I want to edit the hex from a gamesave then save it.
     
  11. Nothinbeter2do

    Nothinbeter2do Banned

    Messages:
    2,425
    Ratings:
    526
    Code:
                  
    Try
    Dim FileName = New FileStream(SaveFile, FileMode.Open, FileAccess.Write, FileShare.Write)
    Dim writer = New BinaryWriter(FileName)
    writer.BaseStream.Position = &H0
    Dim val1 As Integer = Integer.Parse("EDITED TEXT")
    writer.Write(val1)
    writer.Close()
    MessageBox.Show("Changes have been saved!", "Done")
    Catch generatedExceptionName As Exception
    MessageBox.Show("Some kind of error..", "Error")
    End Try
    

    SaveFile is the location of the file you're editing.
     

Share This Page