https://foro.gambas-es.org/viewtopic.php?f=5&t=6198
-----------------------------------
vuott
Domingo, 19 Febrero 2017, 15:24

Simple Editor Hexadecimal
-----------------------------------
Hola,
dejo el código de un simple Editor Hexadecimal para ver y eventualmente modificar el byte de un cualquier archivo:

[code linenumbers=false syntax=gambas]Private TableView1 As TableView


Public Sub Form_Open()

  Dim Menu1 As Menu
  Dim mn1 As Menu
  Dim mn2 As Menu
  Dim mn3 As Menu
  Dim b As Byte

   With Me
     .W = 480
     .H = 500
     .Caption = "Editor Hexadecimal"
   End With
  
   With TableView1 = New TableView(Me) As "TableView1"
     .X = 15
     .Y = 15
     .W = 446
     .H = 400
     .Font.Size = 12
     .Rows.Count = 1
     .Columns.Count = 16
   End With
   
   For b = 0 To TableView1.columns.Max
      TableView1.Columns[b].W = TableView1.W / 16
    Next  
   TableView1[0, 0].Text = "00"
  
   With Menu1 = New Menu(Me)
     .Caption = "File"
   End With
  
   With mn1 = New Menu(Menu1, False) As "mn1"
     .Caption = "Abrir archivo"
     .Name = "Abrir"
   End With
  
   With mn2 = New Menu(Menu1, False) As "mn2"
     .Caption = "Guardar con nombre..."
     .Name = "Guardar con nombre..."
   End With
  
   With mn3 = New Menu(Menu1, False) As "mn3"
     .Caption = "Salir"
     .Name = "Salir"
   End With

End


Public Sub mn1_Click()

  Dim s As String
  Dim bb As Byte[]
  Dim i, r As Integer
  Dim b As Byte
  
    With Dialog
      .Title = "Abrir archivo"
      If .OpenFile() Then Return
      s = .Path
    End With
    
    bb = Byte[].FromString(File.Load(s))
    If (bb.Count Mod 16) > 0 Then TableView1.Rows.Count = (bb.Count \ 16) + 1
   For b = 0 To TableView1.columns.Max
     TableView1.Columns[b].W = TableView1.W / 16
   Next
  
    For r = 0 To TableView1.Rows.Max
      For b = 0 To 15
        TableView1[r, b].Text = Hex(bb[i], 2)
        Inc i
        If i > bb.Max Then Break
      Next
    Next

End


Public Sub mn2_Click()

  Dim ss As New String[]
  Dim r As Integer
  Dim b As Byte
    
    For r = 0 To TableView1.Rows.Max
      For b = 0 To 15
        If TableView1[r, b].Text = Null Then Break
        ss.Push(MkByte(Val("&" & TableView1[r, b].Text)))
      Next
    Next
    
    With Dialog
      .Title = "Guardar archivo con nombre..."
      If .SaveFile() Then Return
      File.Save(.Path, ss.Join(Null, Null))
    End With

End


Public Sub mn3_Click()
  
  Me.Close
  
End


Public Sub TableView1_Click()
  
  TableView1.Edit
  
End


Public Sub TableView1_Save(Row As Integer, Column As Integer, Value As String)
  
  TableView1[Row, Column].Text = Value
  
End[/code]


-----------------------------------
v3ctor
Domingo, 19 Febrero 2017, 16:01

Re: Simple Editor Hexadecimal
-----------------------------------
Muy bueno...


