First we add a further menu item, for opening the file in hex display. Then we add some code to the "onClick" event-handler, to receive the name of the chosen file. The next stage is to read the file and store it byte-by-byte.
In Euphoria the "rb" mode in the open
function enables binary reading of
the relevant file. So open the file in this way. Add to the event handler a
while
loop to add characters to an empty sequence until end-of-file (-1) is
reached. The code parallels that for the standard reading described earlier.
We then loop through the file's contents, copying the characters in hex format, padded with a space, to a buffer and using a second buffer to store the same (ascii) characters for the line output. Every 16 characters we copy this line buffer to the main buffer and clear the line buffer for the next 16 characters.
We need to include code for two circumstances:
At this stage I am setting the "Styles" Property of the Rich Text Edit to "read only" so you can look at the contents of the file but not change them. This is done by finding the relevant "Styles" group in the "Properties" window and ticking (checking) the "Read Only" CheckBox.
My suggested coding is stored in "TextView3.prj" and hence in "TextView3.exw".
Now move on to Stage 4.