#!/bin/sh # # This is a shell archive. To extract its contents, # execute this file with /bin/sh to create the file(s): # # msg_pmpt.4gl msg_pmpt.msg # # This shell archive created: Fri Mar 18 09:51:54 EST 1994 # echo "Extracting file msg_pmpt.msg" sed -e 's/^X//' <<\SHAR_EOF > msg_pmpt.msg XNewsgroups: comp.databases.informix XSubject: A message-in-a-box-and-give-the-user-choice 4gl function XFrom: kerry@kcbbs.gen.nz (Kerry Sainsbury) XDate: Tue, 15 Mar 1994 00:01:40 -0500 X X X ---------------------------------------------- X | CHOOSE: Yes No | X | | X | message_prompt.4gl is a really handy little | X | routine which lets you create cute message | X | boxes for your users, without YOU having to | X | do very much thinking at all. | X | | X | Try it, you'll like it! | X ---------------------------------------------- X X Xeg: LET l_text = "WARNING:<", X "This option will delete all stock records ", X "for this warehouse, are you SURE that this ", X "is REALLY what you want to do?" X IF message_prompt(l_text,"Yes,No")="Yes" THEN X CALL delete_everything() X END IF X Xor, for when you just want to tell the user something happened: X X CALL message_prompt("Batch updated successfully!","") X XNote that a null second parameter means that nothing is returned. X XEnjoy! XKerry Sainsbury Xkerry@kcbbs.gen.nz X XBTW: If you have any code that hogs temporary string space X you can guarantee that this routine will find it! SHAR_EOF if [ `wc -c < msg_pmpt.msg` -ne 1484 ] then echo "Lengths do not match -- Bad Copy of msg_pmpt.msg" fi echo "Extracting file msg_pmpt.4gl" sed -e 's/^X//' <<\SHAR_EOF > msg_pmpt.4gl X{ SCCS ID: @(#)coxxx03.4gl 1.5 94/03/14 22:57:07 } X{****************************************************************************** X* Filename : coxxx03.4gl * X* System : Eunice 4GL - Common Module * X* Purpose : Display text in a box and let user choose an option * X* Returns : Option user chose * X* Author : Kerry S * X* Date Written : 04/10/93 * X* Last Change : * X* * X* 07/10/93 Kerry S - Made code far more re-usable by splitting into * X* setup_wwrap and next_wwrap functions. * X* 29/10/93 Kerry S - Hard returns were not working since above mod * X* 10/11/93 Kerry S - If only option is "Exit", don't return a value * X* * X*******************************************************************************} X X#! message_prompt(l_text, l_menu_commands) RETURNING l_choice X#! - Displays "l_text" in a window on-screen, and prompts the user X#! to make a choice from a ring menu list passed as a comma-delimted X#! string. The function returns the user's selection. X#! X#! eg: LET l_text = "WARNING:<", X#! "This option will delete all stock records ", X#! "for this warehouse, are you SURE that this ", X#! "is REALLY what you want to do?" X#! IF message_prompt(l_text,"Yes,No")="Yes" THEN X#! CALL delete_everything() X#! END IF X#! or: X#! CALL message_prompt("Batch updated successfully!","") X#! X#! X#! NOTE: See coxxx06.4go for an Informix 4.0 version of this routine X#! X# l_text - Text to display in window. X# - The "<" character is interpreted as a hard-return. X# - l_text is currently limited to 800 characters X# l_commands - Commands to place in ring menu, delimited by commas X# eg: "Yes,No" gives the user two options X# - A null "l_command" generates an "Exit" option X# - Only 5 options of 10 characters may be placed in X# the l_command string. X# l_choice - The full text of the ring menu choice the user chose X# X#! setup_wwrap(l_text, l_width) RETURNING l_depth X#! - Sets up a long text string for word-wrapping within l_width X#! characters. X#! X#! next_wwrap() RETURNING l_formated_text X#! - Returns formatted text line, being l_width characters of the X#! l_text string passed to setup_wwrap(). X# X# eg: LET l_depth = setup_wwrap(l_long_text_string, 40) X# FOR i = 1 TO l_depth X# LET l_formated_to_40_characters_string = next_wwrap() X# PRINT l_formatted_to_40_characters_string X# END FOR X# XDEFINE m_text CHAR(800), X m_width SMALLINT, X m_spos SMALLINT X XFUNCTION message_prompt(l_text, l_commands) XDEFINE l_text CHAR(800), X l_commands CHAR(50), X l_line_text CHAR(80), X l_choice CHAR(10), X l_width SMALLINT, X l_depth SMALLINT, X l_col SMALLINT, X l_row SMALLINT, X i SMALLINT X X IF l_commands IS NULL THEN X LET l_commands = "Exit" X END IF X X LET l_width = 50 X X# Calculate depth of box... X X LET l_depth = setup_wwrap(l_text, l_width) X LET l_depth = l_depth + 3 X X LET l_col = (80 - l_width) / 2 X LET l_row = (20 - l_depth) / 2 X X OPEN WINDOW msgbox AT l_row, l_col X WITH l_depth ROWS, l_width COLUMNS X ATTRIBUTE(BORDER, YELLOW) X X# Display message text... X X LET l_depth = l_depth - 3 X LET l_row = 3 X FOR i = 1 TO l_depth X LET l_line_text = next_wwrap() X DISPLAY l_line_text AT l_row, 1 ATTRIBUTE(NORMAL) X LET l_row = l_row + 1 X END FOR X X# Let user select choice from ring menu... X X LET l_choice = coxxx03_varimenu(l_commands) X CLOSE WINDOW msgbox X X IF l_commands != "Exit" THEN X RETURN l_choice X END IF XEND FUNCTION X X XFUNCTION setup_wwrap(l_text, l_width) XDEFINE l_text CHAR(800), # Text string to be formatted X l_width SMALLINT, # Width of the box X l_depth SMALLINT, # Depth of the box X l_lth SMALLINT, # Length of entire text string X l_ret_text CHAR(1) X X LET m_width = l_width X LET m_text = l_text X LET l_depth = 0 X X LET l_lth = length(m_text) X LET m_spos = 1 X WHILE m_spos <= l_lth X LET l_ret_text = coxxx03_study_text() X LET l_depth = l_depth + 1 X END WHILE X LET m_spos = 1 X LET m_text = l_text X RETURN l_depth XEND FUNCTION X X XFUNCTION next_wwrap() XDEFINE l_text CHAR(132) X X LET l_text = coxxx03_study_text() X RETURN l_text XEND FUNCTION X XFUNCTION coxxx03_study_text() XDEFINE l_line_text CHAR(132), # Single formated line to output X l_epos SMALLINT, # End position in text string X l_hp SMALLINT # Hard-return position ("<") X X# First look for a white-space to end the line on... X FOR l_epos = m_spos + m_width TO m_spos STEP -1 X IF m_text[l_epos]=" " THEN X EXIT FOR X END IF X END FOR X IF m_spos >= l_epos THEN # Could not find a white-space, so X LET l_epos = m_spos + m_width # just chop off end of word X END IF X FOR l_hp = m_spos TO l_epos # Have a look for hard-return code... X IF m_text[l_hp]="<" THEN # Found it... X LET l_epos = l_hp X LET m_text[l_hp]=" " X EXIT FOR X END IF X END FOR X LET l_line_text = m_text[m_spos, l_epos] # This is our text to output X X LET m_spos = l_epos + 1 X RETURN l_line_text XEND FUNCTION X X XFUNCTION coxxx03_varimenu(l_commands) XDEFINE i SMALLINT, X l_lth SMALLINT, X l_cnt SMALLINT, X l_s SMALLINT, X l_commands CHAR(50), X la_opt ARRAY[5] OF CHAR(10), X l_choice CHAR(10), X l_menu_name CHAR(10) X X# First determine which options are required... X X LET l_cnt = 1 X LET l_s = 1 X LET l_lth = LENGTH(l_commands) X FOR i = 1 TO l_lth X IF l_commands[i,i]="," THEN X LET la_opt[l_cnt] = l_commands[l_s, i-1] X LET l_s = i + 1 X LET l_cnt = l_cnt + 1 X END IF X END FOR X LET la_opt[l_cnt] = l_commands[l_s, l_lth] X X IF l_cnt = 1 THEN X LET l_menu_name = "MESSAGE" X ELSE X LET l_menu_name = "SELECT" X END IF X X# The following code is something that I find very embarrassing, but it's X# necessary if this routine is going to perform well for the user... X X CASE X WHEN l_cnt = 1 X MENU l_menu_name X COMMAND la_opt[1] X LET l_choice = la_opt[1] X EXIT MENU X END MENU X X WHEN l_cnt = 2 X MENU l_menu_name X COMMAND la_opt[1] X LET l_choice = la_opt[1] X EXIT MENU X COMMAND la_opt[2] X LET l_choice = la_opt[2] X EXIT MENU X END MENU X X WHEN l_cnt = 3 X MENU l_menu_name X COMMAND la_opt[1] X LET l_choice = la_opt[1] X EXIT MENU X COMMAND la_opt[2] X LET l_choice = la_opt[2] X EXIT MENU X COMMAND la_opt[3] X LET l_choice = la_opt[3] X EXIT MENU X END MENU X X WHEN l_cnt = 4 X MENU l_menu_name X COMMAND la_opt[1] X LET l_choice = la_opt[1] X EXIT MENU X COMMAND la_opt[2] X LET l_choice = la_opt[2] X EXIT MENU X COMMAND la_opt[3] X LET l_choice = la_opt[3] X EXIT MENU X COMMAND la_opt[4] X LET l_choice = la_opt[4] X EXIT MENU X END MENU X X WHEN l_cnt = 5 X MENU l_menu_name X COMMAND la_opt[1] X LET l_choice = la_opt[1] X EXIT MENU X COMMAND la_opt[2] X LET l_choice = la_opt[2] X EXIT MENU X COMMAND la_opt[3] X LET l_choice = la_opt[3] X EXIT MENU X COMMAND la_opt[4] X LET l_choice = la_opt[4] X EXIT MENU X COMMAND la_opt[5] X LET l_choice = la_opt[5] X EXIT MENU X END MENU X END CASE X X RETURN l_choice XEND FUNCTION SHAR_EOF if [ `wc -c < msg_pmpt.4gl` -ne 8751 ] then echo "Lengths do not match -- Bad Copy of msg_pmpt.4gl" fi echo "Done." exit 0