= "Hello world" in FORTRAN/TK = == A short tutorial == This is a very very short tutorial about "Hello world" in FORTRAN/TK, to demonstrate how easy it is to write a GUI program with FORTRAN/TK. We need to include the "fortrantk.fap" for global pragmas and the "fortrantk.fi" for local function definitions and constants in the main program unit.[[BR]] Then we need to initialize FORTRAN/TK. This is done with the !TkInit command which takes the path of the runtime DLLs as argument and returns NULL if no error occured and a positive value if one occured. We stop with an error message (on the console) if this happens. We assume that the libraries are installed on the system or are in the same directory as the program.[[BR]] Then we 'withdraw' the main window (which would be otherwise still visible) from the screen by issuing the !TkWm command with 'withdraw' as an argument.[[BR]] After this, we just call the !TkMessageBox function to display our important message. We don't need an event loop because we will just return after the call. Refer to your [http://www.tcl.tk/man/tcl8.0/ Tcl/Tk manual] for further information about the [http://www.tcl.tk/man/tcl8.0/TkCmd/messageBox.htm tk_messageBox] function.[[BR]] At the end, we need to unload FORTRAN/TK by calling the !TkUnload function. We output an error message again if !TkUnload returns a positive value.[[BR]] This is a listing of this simple program: {{{ c$include fortrantk.fap include 'fortrantk.fi' if(TkInit('.'c)) & stop 'FORTRAN/TK couldn''t get initialized!' call TkWm('withdraw'c, '.'//dn) call TkMessageBox('-message'c, 'Hello world'c, & '-title'c, 'Test Application'c, & '-icon'c, 'info'//dn) if(TkUnload()) & write(*,*) 'FORTRAN/TK couldn''t get unloaded!' end }}} You can download this file from [ftp://pub.netlabs.org/pub/fortrantk/misc/hello.for here]. This code can be compiled by using the Open Watcom FORTRAN 77 Compile and Link Utility. Of course you have to initialize the necessary Open Watcom environmental variables and add the FORTRAN/TK path to the FINCLUDE variable first, eg. if your Watcom directory is "C:\PRG\WATCOM" and your FORTRAN/TK path is "C:\PRG\FORTRANTK" by issuing:[[BR]] for OS/2: {{{ C:\PRG\WATCOM\SETVARS.CMD }}} or for Windows: {{{ C:\PRG\WATCOM\SETVARS.BAT }}} and finally {{{ set FINCLUDE=%FINCLUDE%;C:\PRG\FORTRANTK }}} on the commandline.[[BR]] Assuming that you called your file "HELLO.FOR" and your FORTRAN/TK library is in the current directory you would have to enter:[[BR]] for OS/2: {{{ wfl386 hello.for fortrantk.lib -FE=hello.exe -BM -DEF=__OS2__ -L=OS2V2 }}} or for Windows: {{{ wfl386 hello.for fortrantk.lib -FE=hello.exe -BM -DEF=__WIN__ -L=NT }}} That's it - now you can run "HELLO.EXE" on your preferred system, but don't forget to put the Rexx/Tk and Tcl/Tk libraries in the current directory unless you defined another directory containing the libs using !TkInit. It's now compiled as a console program, so it features a console window.[[BR]] Here's a screenshot of the "Hello world" program running under Windows XP: {{{ #!html
}}}