A customer recently asked how to read some input from the user in XJEase. The next major release of XJTAG (probably numbered 2.4) will contain a new XJEase function INPUTBOX that makes doing this much simpler. In the meantime, I thought I might outline some code that accomplishes the same thing in the current version.
The core of the code is a loop that simply calls the WAITKEY function to read a character of input at a time, until a carriage return is read. As each character is read it is appended to a string that will be returned and also printed to the screen.
This works reasonably well until the user makes a mistake and wants to backspace. Handling backspace requires us to print the backspace character and remove the last character from the string that we’re building. We can also check the current length of the input string and not allow the user to backspace beyond its start.
The full function appears below, plus an example of its use. It is named INPUTBOX and has the same signature as the upcoming XJEase built-in function, which means once the new version of XJTAG arrives, this function can be deleted and the code will then continue to work. The 3 arguments are the prompt to display, a title and a string that is presented as the default (can be left as an empty string). Note that the example below simply prints the title out, whereas the real INPUTBOX will create a proper dialog box.Note also the use of the ALERT function. If you have more than one XJLink attached in XJRunner, then the output from each is displayed in its own tab; the ALERT function causes the application to draw attention to any tab that requires attention. In XJDeveloper or in XJRunner with just one XJLink attached, then the function has no effect.