Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

CONsole SELECT

Aug
1,914
68
Hi,
Below is a program that I wrote, which is by no means a polished, finished product. I am just passing it along in the event someone else finds it useful like I do.

Please feel free to make any changes or improvements to the code.

Joe

Code:
***********************************************************************
* CON_SELECT.PRG
*
* Displays a console window to select a line from a file,
*   similar to the TCC variable function @select
*
* After using this program to select a line, the line number is
*   returned to the command processor via the ERRORLEVEL.
*
* Pressing ESC returns an ERRORLEVEL of 0 (zero).
*
* Refer to TEST.BTM for an example of this programs use.
*
* Written using the Harbour Compiler, available from
*   http://www.harbour-project.org/
*
* Harbour is a free, open-source, 100% Compatible Clipper compiler
*
* September 2011, Joe Caverly
***********************************************************************
PROC Main()
  PARAMETERS cFileName, nTop, nLeft, nBottom, nRight

  LOCAL cString
  LOCAL cScr
  LOCAL nCurrentLine
  LOCAL aArray := {}

  IF PCOUNT() < 5
    ? "USAGE: CON_SELECT FileName, Top, Left, Bottom, Right"
    QUIT
  ENDIF

  *
  * See if the file exists
  *
  IF FILE(cFileName)
    cString := MEMOREAD(cFileName)
  ELSE
    ? "Error reading the file"
    QUIT
  ENDIF

  SETCOLOR("W+/N, BG+/B, , , W/N")
  
  cScr := SAVESCREEN( VAL(nTop)-1, VAL(nLeft)-1, VAL(nBottom)+1, VAL(nRight)+1 )

  @ VAL(nTop)-1, VAL(nLeft)-1 to VAL(nBottom)+1, VAL(nRight)+1  
  
  nLines := MLCOUNT(cString)
  nLineLength := VAL(nRight)

  FOR nCurrentLine := 1 TO nLines
    AADD(aArray, MEMOLINE(cString, nLineLength, nCurrentLine, , ))
  NEXT

  nPosition := ACHOICE( VAL(nTop), VAL(nLeft), VAL(nBottom), VAL(nRight), aArray)
  
  RESTSCREEN( VAL(nTop)-1, VAL(nLeft)-1, VAL(nBottom)+1, VAL(nRight)+1, cScr )
  
  ERRORLEVEL(nPosition)
RETURN
With harbour installed (I am using Version 3), you build the above program into an EXE by issuing the following;

Code:
hbmk2 -shared -strip con_select.prg
Code:
::*****************************************
::* TEST.BTM
::*
::* Demonstrates how to use CON_SELECT.EXE
::*****************************************
@setlocal
@echo off
set thefile=con_select.prg
con_select.exe %thefile 5 7 20 180
set theline=%?
iff %theline gt 0 then
  echo %@line[%thefile, %@eval[%theline-1]]
else
  echo No selection was made
endiff
msgbox ok "ERRORLEVEL" %?
endlocal
 
Back
Top