AChoice()

 

ACHOICE()

Allows selection of an element from an array

Syntax

      ACHOICE(<nTop>, <nLeft>, <nBottom>, <nRight>,;
              <acMenuItems>, [<alSelableItems> | <lSelableItems>],;
              [<cUserFunction> | <bUserBlock>], [<nInitialItem>],;
              [<nWindowRow>]) --> nPosition

Arguments

<nTop> – topmost row used to display array (default 0)

<nLeft> – leftmost row used to display array (default 0)

<nBottom> – bottommost row used to display array (default MaxRow())

<nRight> – rightmost row used to display array (default MaxCol())

<acMenuItems> – the character array of items from which to select

<alSelableItems> – an array of items, either logical or character, which is used to determine if a particular item may be selected. If the type of a given item is character, it is macro evaluated, and the result is expected to be a logical. A value of .T. means that the item may be selected, .F. that it may not. (See next argument: lSelectableItems)

<lSelableItems> – a logical value which is used to apply to all items in acMenuItems. If .T., all items may be selected; if .F., none may be selected. (See previous argument: alSelectableItems) Default .T.

<cUserFunction> – the name of a function to be called which may affect special processing of keystrokes. It is specified without parentheses or parameters. When it is called, it will be supplied with the parameters: nMode, nCurElement, and nRowPos. Default NIL.

<bUserBlock> – a codeblock to be called which may affect special processing of keystrokes. It should be specified in the form {| nMode, nCurElemenet, nRowPos | ; MyFunc( nMode, nCurElemenet, nRowPos ) }. Default NIL.

<nInitialItem> – the number of the element to be highlighted as the current item when the array is initially displayed. 1 origin. Default 1.

<nWindowRow> – the number of the window row on which the initial item is to be displayed. 0 origin. Default 0.

Returns

<nPosition> – the number of the item to be selected, or 0 if the selection was aborted.

Description

Allows selection of an element from an array. Please see standard CA-Cl*pper documentation for ACHOICE for additional detail.

Examples

      aItems := { "One", "Two", "Three" }
      nChoice := AChoice( 10, 10, 20, 20, aItems )
      IF nChoice == 0
         ? "You did not choose an item"
      ELSE
         ? "You chose element " + hb_ntos( nChoice )
         ?? " which has a value of " + aItems[ nChoice ]
      ENDIF

Files

Library is rtl

Compliance

Clipper

Seealso

MENU TO

Advertisements

__MenuTo()

Template

Function

Name

__MenuTo()

Category

API

Subcategory

User interface

Oneliner

Invoked a menu defined by set of @…PROMPT

Syntax

      __MenuTo( <bBlock>,  <cVariable> ) --> nChoice

Arguments

<bBlock> is a set/get code block for variable named <cVariable>.

<cVariable> is a character string that contain the name of the variable to hold the menu choices, if this variable does not exist a PRIVATE variable with the name <cVariable> would be created to hold the result.

Returns

__MenuTo() return the number of select menu item, or 0 if there was no item to select from or if the user pressed the Esc key.

Description

__MenuTo() invoked the menu define by previous __AtPrompt() call and display a highlight bar that the user can move to select an option from the menu. If <cVariable> does not exist or not visible, a PRIVATE variable named <cVariable> is created and hold the current menu selection. If there is a variable named <cVariable>, its value is used to select the first highlighted item.

Menu prompts and messages are displayed in current Standard color, highlighted bar is displayed using current Enhanced color.

Pressing the arrow keys move the highlighted bar. When a menu item is highlighted the message associated with it is displayed on the line specified with SET MESSAGE. If SET WRAP is ON and the user press UP arrow while on the first selection the last menu item is highlighted, if the user press Down arrow while on the last item, the first item is highlighted.

Following are active keys that handled by __MenuTo():

       key            Meaning
       -------------  ---------------------------------
       Up             Move to previous item
       Down           Move to next item
       Left           Move to previous item
       Right          Move to next item
       Home           Move to the first item
       End            Move to the last item
       Page-Up        Select menu item,  return position
       Page-Down      Select menu item,  return position
       Enter          Select menu item,  return position
       Esc            Abort selection,  return 0
       First letter   Select next menu with the same first letter, |return this item position.

Upon exit the cursor is placed at MaxRow()-1, 0 __MenuTo() can be nested without loosing the previous  prompts.

MENU TO command is preprocessed into __MenuTo() function during compile time.

Examples

      // display menu item on each screen corner and let user select one
      CLS
      SET MESSAGE TO MaxRow() / 2 CENTER
      SET WRAP ON
      @ 0           ,  0             PROMPT "1. Upper left"   MESSAGE " One "
      @ 0           ,  MaxCol() - 16 PROMPT "2. Upper right"  MESSAGE " Two "
      @ MaxRow() - 1,  MaxCol() - 16 PROMPT "3. Bottom right" MESSAGE "Three"
      @ MaxRow() - 1,  0             PROMPT "4. Bottom left"  MESSAGE "Four "
      MENU TO nChoice
      SetPos( MaxRow() / 2,  MaxCol() / 2 - 10 )
      IF nChoice == 0
         ?? "Esc was pressed"
      ELSE
         ?? "Selected option is",  nChoice
      ENDIF

Compliance

Clipper

Files

Library is core

Seealso

@…PROMPT, AChoice(), SET MESSAGE, SET INTENSITY, SET WRAP, __AtPrompt()

__AtPrompt()

Template

Function

Name

__AtPrompt()

Category

API

Subcategory

User interface

Oneliner

Display a menu item on screen and define a message

Syntax

      __AtPrompt( <nRow>,  <nCol>,  <cPrompt>,  [<xMsg>] ) --> .F.

Arguments

<nRow> is the row number to display the menu <cPrompt>. Value could range from zero to MaxRow().

<nCol> is the column number to display the menu <cPrompt>. Value could range from zero to MaxCol().

<cPrompt> is the menu item character string to display.

<xMsg> define a message to display each time this menu item is highlighted. <xMsg> could be a character string or code block that is evaluated to a character string. If <xMsg> is not specified or of the wrong type, an empty string (“”) would be used.

Returns

__AtPrompt() always return .F.

Description

With __AtPrompt() you define and display a menu item, each call to __AtPrompt() add another item to the menu, to start the menu itself you should call the __MenuTo() function (MENU TO command). You can define any row and column combination and they will be displayed at the order of definition. After each call to __AtPrompt(), the cursor is placed one column to the right of the last text displayed, and Row() and Col() are updated.

@…PROMPT command is preprocessed into __AtPrompt() function during compile time.

Examples

      // display a two line menu with status line at the bottom
      // let the user select favorite day
      SET MESSAGE TO 24 CENTER
      @ 10,  2 PROMPT "Sunday" MESSAGE "This is the 1st item"
      @ 11,  2 PROMPT "Monday" MESSAGE "Now we're on the 2nd item"
      MENU TO nChoice
      DO CASE
      CASE nChoice == 0           // user press Esc key
         QUIT
      CASE nChoice == 1           // user select 1st menu item
         ? "Guess you don't like Mondays"
      CASE nChoice == 2           // user select 2nd menu item
         ? "Just another day for some"
      ENDCASE

Compliance

C (menu)

Files

Library is core

Seealso

AChoice(), MENU TO, SET MESSAGE, SET INTENSITY, SET WRAP, __MenuTo()

@…PROMPT

@…PROMPT

Display a menu item on screen and define a message

Syntax

      @ <nRow>, <nCol> PROMPT <cPrompt> [MESSAGE <xMsg>]

Arguments

<nRow> is the row number to display the menu <cPrompt>. Value could range from zero to MaxRow().

<nCol> is the column number to display the menu <cPrompt>. Value could range from zero to MaxCol().

<cPrompt> is the menu item character string to display.

<xMsg> define a message to display each time this menu item is highlighted. <xMsg> could be a character string or code block that is evaluated to a character string. If <xMsg> is not specified or of the wrong type, an empty string (“”) would be used.

Description

With @…Prompt you define and display a menu item, each call to @…Prompt add another item to the menu, to start the menu itself you should call the __MenuTo() function (MENU TO command). You can define any row and column combination and they will be displayed at the order of definition. After each call to @…Prompt, the cursor is placed one column to the right of the last text displayed, and ROW() and COL() are updated.

@…PROMPT command is preprocessed into __AtPrompt() function during compile time.

Examples

      // display a two line menu with status line at the bottom
      // let the user select favorite day
      SET MESSAGE TO 24 CENTER
      @ 10, 2 PROMPT "Sunday" MESSAGE "This is the 1st item"
      @ 11, 2 PROMPT "Monday" MESSAGE "Now we're on the 2nd item"
      MENU TO nChoice
      DO CASE
      CASE nChoice == 0           // user press Esc key
         QUIT
      CASE nChoice == 1           // user select 1st menu item
         ? "Guess you don't like Mondays"
      CASE nChoice == 2           // user select 2nd menu item
         ? "Just another day for some"
      ENDCASE

Compliance

Clipper (menu)

Seealso

ACHOICE(), MENU TO, SET MESSAGE, SET INTENSITY, SET WRAP, __MENUTO()

What is Superlib ?

Superlib Description by Oasis 

The final version of SuperLib, and now it’s FREEWARE, and it comes with 100% SOURCE CODE and extensive norton guide.

SuperLib is a library of functions for Clipper 5.x.

What makes SuperLib different than other libraries on the marketplace is that is contains a large collection of METAFUNCTIONS. A metafunction is like a pre-packaged mini application, ready to link and run. For instance, SuperLib’s report writer is as simple to use as:

USE
REPORTER()

All of the metafunctions are menu-driven and ready to use without modifications. All SuperLib functions are data independant. All that is required is an open DBF file. SuperLib will determine the field structure and use the current DBF. SuperLib requires no special setup or way of doing things. It works with you, not against you. SuperLib functions will do their best to save/restore all settings as they found them. (such as colors, cursor, screens, etc.)

There are over 300 functions in SuperLib, ranging from the metafunctions down to the granular common component functions such as events and popups. (see the function list below, or the .NG file). This version of SuperLib is 100% mouse aware! All SuperLib functions
are automatically aware of the mouse and respond to the mouse.

SuperLib even contains replacements for Clipper’s READ, MENU TO, ACHOICE and MEMOEDIT functions that are mouse aware. Several functions are provided to help you build mouse awareness into your own functions.

SuperLib is Blinker 3.x, 4.x and Exospace compatible for protected mode programs. SuperLib is 99.9 % pure Clipper code, and uses no Clipper internals, which makes for painless upgrading to future versions of Clipper and the various linkers.

SuperLib is network ready, with all locking already built in. (works fine for single-user too)

There is no registration of SuperLib, since it is now freeware. The author, Gary Prefontaine, is no longer supporting the product. If you need help with this library, please ask on comp.lang.clipper

Thanks, Gary.

http://www.the-oasis.net/files/library/supfree.zip

http://www.the-oasis.net/supfree.htm

SP_SACHOICE

SACHOICE()

  Short:
  ------
  SACHOICE() Achoice replacement, uses TBROWSE, codeblock

  Returns:
  --------
  <nSelection> => selection, 0 if none

  Syntax:
  -------
  SACHOICE(nTop,nLeft,nBottom,nRight,aOptions,[bKeyBlock],[nStart],[@nRow],;
           [nMRow, nMCol],[bMouse])

  Description:
  ------------
  This semi-replaces ACHOICE() by using TBROWSE
  instead, and by accepting an exception codeblock instead of a user
  defined function.

  <nTop,nLeft,nBottom,nRight> are the dimensions.

  <aOptions> is the array. It need not be of type
  Character.

  First-letter presses go to the next matching letter
  of the next character-type element.
  Up/down/home/end/pageup/pagedown are used to position the
  cursor. ENTER returns the current selection. Escape returns 0.

  The screen is not saved and restored. This is a
  building block function, like ACHOICE(), so save and restore the
  screen, draw a box around it, etc, as you would ACHOICE().

  [bKeyBlock] a codeblock which will be executed if an
  exception key is received (any key not otherwise meaningful). The
  codeblock will be evaluated and will be passed:

           1. current element #
           2. exception key value
           3. the tbrowse object

  as parameters.

  [nStart] is an optional starting element. Default is 1.
  [@nRow] is an optional starting row. Default is 1. Pass by reference
  to retain value between calls.

  [nMRow, nMCol]  (new in 3.5) Directs sachoice() to draw
  the "[.][.]" for mouse up/down at nMrow, nMCol, and to be aware of mouse
  clicks on these buttons. (the screen under the arrows is saved/restored)

  [bMouse] is a codeblock to evaluate mouse clicks other than those
  meaningful to sachoice(). The codeblock is evaluated as follows:
            eval(bMouse,mouserow, mousecolumn)

  Examples:
  ---------
   USE CUSTOMER

   aFlds       := afieldsx()
   bExcept     := {|e,k|msg("You pressed ",str(k))}
   ?SACHOICE(10,10,20,12,aFlds,bExcept)

   //to retain element and position between calls
   nSelect := 1
   nRow    := 1
   aMeals   := {"Pizza","Chicken","Chinese"}
   while nSelect > 0
     nSelect  := sachoice(10,10,20,20,aMeals,nil,nSelect,@nRow)
     // code
   endif

  Notes:
  -------
  This will be a lot easier to mouse-ize than ACHOICE.
  (or is that RAT-ify..)

  Source:
  -------
  S_ACHOI.PRG

 

SP_POPEX

POPEX()

  Short:
  ------
  POPEX() Pops up an achoice for a certain filespec

  Returns:
  --------
  <cFileName> => file name or "" for none

  Syntax:
  -------
  POPEX(cSkel,[cTitle])

  Description:
  ------------
  Pops up a picklist for all files matching the
  skeleton given as <cSkel>. i.e. "*.dbf"

  If a path is passed, the path is returned as part of
  the filename.

  Optional title string [cTitle] - displays at top of
  box

  Examples:
  ---------
   cOpendbf := POPEX("*.DBF")
       // => will return DBF name

   opendbf = POPEX("C:\FILES\*.DBF")
       // => will return "C:\FILES\" plus DBF name

  Source:
  -------
  S_POPEX.PRG