Author Topic: [PBCC] Alphanumeric line editor  (Read 3671 times)

0 Members and 1 Guest are viewing this topic.

Offline José Roca

  • Administrator
  • Hero Member
  • *****
  • Posts: 2481
  • User-Rate: +204/-0
[PBCC] Alphanumeric line editor
« on: August 29, 2011, 06:54:40 PM »
 
Handy routines to edit strings and numbers in the console compiler.

Code: [Select]
' ========================================================================================
' EdStr - Alphanumeric editor
' ========================================================================================
'
' vbTxt = String to edit
' vbFmt : "#" Numbers only
'         "-" Negative numbers
'         "M" Converts to upper case
'         "m" Converts to lower case
'         "P" Pasword (shows asterisks)
'         "," Separates thousands with commas
'         "." Separates thousands with colons
'         "L" Left justified and padded with spaces
'         "R" Right justified and padded with spaces
'         "l" Left justified and padded with zeros
'         "r" Right justified and padded with zeros
'         "S" Trims leading spaces
'         "s" Trims trailing spaces
'         "T" Trims leading and trailing spaces
'         "X" Ends the edition when the limit is reached
' vbLin = Screen line
' vbCol = Screen column
' vbInt = Number of digits if it is a number
'         Number of characters if it is a string
' vbDec = Number of decimal digits
' vbEditStartPos = Starting edit position
' vbMax = Maximum visible width (can be smaller than the length of the string to edit)
' vbAttr = HSW color attributes
'
' Return Value: The edited string.
' ========================================================================================

FUNCTION EdStr (BYVAL vbTxt AS STRING, BYVAL vbFmt AS STRING, BYVAL vbLin AS LONG, _
                BYVAL vbCol AS LONG, BYVAL vbInt AS LONG, _
                OPTIONAL BYVAL vbDec AS LONG, BYVAL vbEditStartPos AS LONG, _
                BYVAL vbMax AS LONG, BYVAL vbAttr AS LONG, BYVAL vbEscKeys AS STRING _
                ) AS STRING

Code: [Select]
' ========================================================================================
' EdNum - Calculator-like numeric string editor
' ========================================================================================
' vbNum  = Number to edit
' vbFmt  :   , = Separate thousands with commas
'            . = Separate thousands with colons
'            - = Accepts negative numbers
'            C = Calculator
' vbLin  = Screen line
' vbCol  = Screen column
' vbEnt  = Number of digits
' vbDec  = Number of decimals
' vbAttr = HSW color attributes
' To edit decimals, press the "." key
' To make the number negative, press the "-" key
' To make the number positive, press the "+" key or again the "-" key
' ========================================================================================

FUNCTION EdNum (BYVAL vbNum AS EXT, _
                BYVAL vbFmt AS STRING, _
                BYVAL vbLin AS LONG, _
                BYVAL vbCol AS LONG, _
                BYVAL vbInt AS LONG, _
                OPTIONAL BYVAL vbDec AS LONG, _
                BYVAL vbAttr AS LONG, _
                BYVAL vbEscKeys AS STRING _
                ) AS EXT

Small test:

Code: [Select]
' SED_PBCC - Use the PBCC compiler
#COMPILE EXE
#DIM ALL
#INCLUDE "EDSTR.INC"

FUNCTION PBMAIN () AS LONG

   LOCAL strTest AS STRING
   LOCAL Num AS DOUBLE

   strTest = EdStr(strTest, "-", 7, 8, 40, 0, 0, 30, EdColorAttr(15, 3))
   strTest = "12345"
   strTest = EdStr(strTest, "-", 9, 8, 6, 2, 3, 0, EdColorAttr(15, 4))
   Num = EdNum(Num, ",-", 11, 8, 6, 2, EdColorAttr(15, 2))

END FUNCTION

The attached file contains the full code.