Hello everyone
i am a new developper and i am very interested to this great soft AMS 8 it's easy & powerful
i want to build a simple hex viewer & editor and show all bytes to grid object or input ( like this photo )

but the problem : the time of execution is too late when i open a file bigger then 20kb
any suggetion please
how to show all bytes at the same time in the grid object or input ...like the other hex editors ?
my source code
the function
i am a new developper and i am very interested to this great soft AMS 8 it's easy & powerful
i want to build a simple hex viewer & editor and show all bytes to grid object or input ( like this photo )

but the problem : the time of execution is too late when i open a file bigger then 20kb
any suggetion please
how to show all bytes at the same time in the grid object or input ...like the other hex editors ?
my source code
Code:
FilePath = Dialog.FileBrowse(true, "Locate File", _DesktopFolder, "All Files (*.*)|*.*|", "", "dat", false, false); if FilePath[1] == "CANCEL" then Application.ExitScript(); end -- Delete cells from the grid Grid.SetRowCount("Grid1", 1); local f = assert(io.open(FilePath[1], "rb")) local block = 10 binTb = {} --//16 ii = 1;-- number of bytes = i*16 jj = 1;-- count 1 to 16 and return binTb[ii] = {}; -- 16 case = 16 byte while true do local bytes = f:read(block) if not bytes then break end for b in string.gfind(bytes, ".") do if jj == 17 then -- in the 17 ... 1 ( 0 in binaire ) ( 16 byte / binTb[ii] ) ii = ii+1; jj = 1; binTb[ii] = {}; end binTb[ii][jj] = string.format("%02X ", string.byte(b)); jj = jj+1; end end -- Add to grid for i,j in pairs(binTb) do result = Grid.InsertRow("Grid1", -1, false); for ii,jj in pairs(binTb[i]) do Grid.SetCellText("Grid1", i, ii, jj, true); Grid.SetCellColors("Grid1", i, ii, {Background=0,Text=16777215}, false); end Grid.SetCellText("Grid1", i, 0, Dec2Hex(i-1), true); -- start from 0 end for i,j in pairs(binTb) do byte2char = ""; for ii,jj in pairs(binTb[i]) do byte2char = byte2char..jj end Grid.SetCellColors("Grid1", i, 17, {Background=0,Text=16777215}, false); Grid.SetCellText("Grid1", i, 17, byte2char, true); end Grid.Refresh("Grid1");
Code:
function Dec2Hex(nValue) if type(nValue) == "string" then nValue = String.ToNumber(nValue); end nHexVal = string.format("%X", nValue); -- %X returns uppercase hex, %x gives lowercase letters sHexVal = nHexVal..""; return sHexVal; end
Comment