« Risposta #3 il: 19 Febbraio 2017, 18:18:10 »
...ad ogni modo propongo quest'altro codice per un programma più elegante:
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 Esadecimale"
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 = "Apri file"
.Name = "Apri"
End With
With mn2 = New Menu(Menu1, False) As "mn2"
.Caption = "Salva con nome..."
.Name = "Salva con nome..."
End With
With mn3 = New Menu(Menu1, False) As "mn3"
.Caption = "Esci"
.Name = "Esci"
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 = "Apri file"
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 = "Salva file con nome..."
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
Registrato
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »