A working solution - Stage 3

The plan is to create a simple hex editor option where the contents of the file are displayed on blocks of 16 characters. The left-hand area of the display will show the hex codes; the right-hand area showing the ascii-based text.

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:

  1. non-printable characters in the line buffer - add a space for each case
  2. the left overs, if any, when the end is reached.
When all is done we set the contents of the Rich Text Edit area to those of the working buffer. To make a neat and even display we need to set the font to a monospace type (here New Courier 10) and to widen both the Form and the Rich Text Edit to fit each buffer line into the output space.

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.