Euphoria Trouble-Shooting Guide

If you get stuck, here are some things you can do:

1. - Type: guru
followed by some keywords associated with your problem.

For example,
guru declare global include

2. - Check the list of common problems (below).
3. - Read the relevant parts of the documentation, i.e. refman.doc or library.doc.
4. - Try running your program with the statements:
        with trace


at the top of your main .ex file so you can see what's going on.
5. - The Euphoria mailing list has a search facility. You can search the archive of all previous messages. There's a good chance that your question has already been discussed.
6. - Post a message on the mailing list.

Here are some commonly reported problems ( P: ) and their solutions ( S: ).

P: I ran my program with exw and the console window disappeared before I could read the output.
S: The console window will only appear if required, and will disappear immediately when your program finishes execution. Perhaps you should code something like:
        puts(1, "\nPress Enter\n")

        if getc(0) then

        end if

at the end of your program.

P: At the end of execution of my program, I see "Press Enter" and I have to hit the Enter key. How do I get rid of that?
S: Call free_console() just before your program terminates.
        include dll.e



P: I would like to change the properties of the console window.
S: Right click on c:\windows\system\conagent.exe and select "properties". You can change the font and several other items.

P: When I run ex.exe in a DOS Window, it makes my small DOS window go to full screen.
S: This will only happen the first time you run ex.exe after creating a new small DOS window. You can make the window small again by pressing Alt-Enter. It will stay small after that. Your Euphoria program can keep the window small by executing:
        if graphics_mode(-1) then

        end if

at the start of execution. This may cause some brief screen flicker. Your program can force a text window to be full-screen by executing:
        if graphics_mode(3) then

        end if

P: My Euphoria CGI program hangs or has no output
S: Look for an ex.err file in your cgi-bin directory. Turn on with trace / trace(3) to see what statements are executed (see ctrace.out in your cgi-bin). Insert without warning at the top of your program. On Windows, when there are warnings, Euphoria will issue a prompt before terminating, causing your program to hang. On Windows you should always use exwc.exe to run CGI programs, or you may have problems with standard output. With Apache Web Server, you can have a first line in your program of: #!.\exwc.exe to run your program using exwc.exe in the current (cgi-bin) directory. On Linux/FreeBSD, be careful that your first line ends in LF, not CR-LF, or the #! won't be handled correctly. On Linux you must also set the execute permissions on your program correctly, and ex.err and ctrace.out must be writable by the server process or they won't be updated. See cgi.htm for more

P: How do I read/write ports?
S: Get Jacques Deschenes' collection of machine-level and DOS system routines from the Euphoria Web page. See his file ports.e.

P: I'm having trouble running a DOS32 graphics program. I hit control-Break and now my system seems to be dead.
S: Some graphics programs will not run unless you start them from DOS or from a full-screen DOS window under Windows. Sometimes you have to edit the program source to use a lower resolution graphics mode, such as mode 18. Some SVGA graphics modes might not work for you under a DOS window, but will work when you restart your machine in MS-DOS mode. A better driver for your video card might fix this.

You should stop a program using the method that the program documentation recommends. If you abort a program with control-c or control-Break you may find that your screen is left in a funny graphics mode using funny colors. When you type something, it may be difficult or even impossible to read what you are typing. The system may even appear dead, when in fact it is not.

Try the following DOS commands, in the following order, until you clear things up:

1. type: Alt-Enter to get a normal (non-full-screen) window again.

2. type: cls
Even when you can't see any keystrokes echoed on the screen this may clear the screen for you.

3. type: ex
The Euphoria interpreter will try to restore a normal text mode screen for you.

4. type: exit
If you are running under Windows, this will terminate the DOS session for you.

5. type: Control-Alt-Delete
This will let you kill the current DOS session under Windows, or will soft-reboot your computer if you are running under DOS.

6. If all else fails, reset or power your computer off and back on. You should immediately run scandisk when the system comes back up.

P: When I run Euphoria programs in SVGA, the output on the screen is crammed into the top part of the screen.
S: Try: use_vesa(1) in machine.e.

Try downloading the latest driver for your video card from the Internet. ATI's site is:

Others have had their video problems clear up after installing the latest version of DirectX.

P: My program leaves the DOS window in a messy state. I want it to leave me with a normal text window.
S: When your program is finished, it should call the function graphics_mode(-1) to set the DOS window back to normal. e.g.
        if graphics_mode(-1) then

        end if

P: When I run my program from the editor and I hit control-c, the program dies with an operating system error.
S: This is a known problem. Run your program from the command-line, outside the editor, if you might have to hit control-c or control-Break.

P: When I run my program there are no errors but nothing happens.
S: You probably forgot to call your main procedure. You need a top-level statement that comes after your main procedure to call the main procedure and start execution.

P: I'm trying to call a routine documented in library.doc, but it keeps saying the routine has not been declared.
S: Did you remember to include the necessary .e file from the euphoria\include directory? If the syntax of the routine says for example, "include graphics.e", then your program must have "include graphics.e" (without the quotes) before the place where you first call the routine.

P: I have an include file with a routine in it that I want to call, but when I try to call the routine it says the routine has not been declared. But it has been declared.
S: Did you remember to define the routine with "global" in front of it in the include file? Without "global" the routine is not visible outside of its own file.

P: How do I input a line of text from the user?
S: See gets() in library.doc. gets(0) will read a line from standard input, which is normally the keyboard. The line will always have \n on the end. To remove the trailing \n character do:
        line = line[1..length(line)-1]

Also see prompt_string() in get.e.

P: After inputting a string from the user with gets(), the next line that comes out on the screen does not start at the left margin.
S: Your program should output a new-line character e.g. puts(SCREEN, '\n') after you do a gets(). It does not happen automatically.

P: Why aren't my floating-point calculations coming out exact?
S: Intel CPU's, and most other CPU's, use binary numbers to represent fractions. Decimal fractions such as 0.1, 0.01 and similar numbers can't be represented precisely. For example, 0.1 might be stored internally as 0.0999999999999999. That means that 10 * 0.1 might come out as 0.999999999999999, and floor(10 * 0.1) might be 0, not 1 as you'd expect. This can be a nuisance when you are dealing with money calculations, but it's not a Euphoria problem. It's a general problem that you must face in most programming languages. Always remember: floating-point numbers are just an approximation to the "real" numbers in mathematics. Assume that any floating-point calculation might have a tiny bit of error in the result. Sometimes you can solve the problem by rounding, e.g. x = floor(x + 0.5) would round x off to the nearest integer. Storing money values as an integer number of pennies, rather than a fractional number of dollars (or similar currency) will help, but some calculations could still cause problems.

P: How do I convert a number to a string?
S: Use sprintf() in library.doc. e.g.
        string = sprintf("%d", number)

Besides %d, you can also try other formats, such as %x (Hex) or %f (floating-point).

P: How do I convert a string to a number?
S: Use value() in library.doc, or, if you are reading from a file or the keyboard, use get().

P: It says I'm attempting to redefine my for-loop variable.
S: For-loop variables are declared automatically. Apparently you already have a declaration with the same name earlier in your routine or your program. Remove that earlier declaration or change the name of your loop variable.

P: I get the message "unknown escape character" on a line where I am trying to specify a file name.
S: Do not say "C:\TMP\MYFILE". You need to say "C:\\TMP\\MYFILE". Backslash is used for escape characters such as \n or \t. To specify a single backslash in a string you need to type \\.

P: I'm trying to use mouse input in a SVGA graphics mode but it just doesn't work.
S: DOS does not support mouse input in modes beyond graphics mode 18 (640x480 16 color). DOS 7.0 (part of Windows 95/98) does seem to let you at least read the x-y coordinate and the buttons in high resolution modes, but you may have to draw your own mouse pointer in the high-res modes. Graeme Burke, Peter Blue and others have good solutions to this problem. See their files on the Euphoria Archive Web page.

P: I'm trying to print a string using printf() but only the first character comes out.
S: See the printf() description in library.doc. You may need to put braces around your string so it is seen as a single value to be printed, e.g. you wrote:
        printf(1, "Hello %s", mystring)

where you should have said:
        printf(1, "Hello %s", {mystring})

P: When I print numbers using print() or ?, only 10 significant digits are displayed.
S: Euphoria normally only shows about 10 digits. Internally, all calculations are performed using at least 15 significant digits. To see more digits you have to use printf(). For example,
        printf(1, "%.15f", 1/3)

This will display 15 digits.

P: It complains about my routine declaration, saying "a type is expected here".
S: When declaring subroutine parameters, Euphoria requires you to provide an explicit type for each individual parameter. e.g.
        procedure foo(integer x, y)         -- WRONG

        procedure foo(integer x, integer y) -- RIGHT

In all other contexts it is ok to make a list:
        atom a, b, c, d, e

P: I'm declaring some variables in the middle of a routine and it gives me a syntax error.
S: All of your private variable declarations must come at the beginning of your subroutine, before any executable statements. (At the top-level of a program, outside of any routine, it is ok to declare variables anywhere.)

P: It says:
Syntax Error - expected to see possibly 'xxx', not 'yyy'
S: At this point in your program you have typed a variable, keyword, number or punctuation symbol, yyy, that does not fit syntactically with what has come before it. The compiler is offering you one example, xxx, of something that would be accepted at this point in place of yyy. Note that there may be many other legal (and much better) possibilities at this point than xxx, but xxx might at least give you a clue as to what the compiler is "thinking".

P: I'm having problems running Euphoria with DR-DOS.
S: Your config.sys should have just HIMEM.SYS but not EMM386.EXE in it.

P: I try to run a program with exw and it says "this is a Windows NT character-mode executable".
S: exw.exe is a 32-bit Windows program. It must be run under Windows or in a DOS Window. It will not work under plain DOS in an old system. ex.exe will work under plain DOS.