Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unlimited Parameters

Status
Not open for further replies.

diesirae

Programmer
May 20, 2003
18
0
0
AR
This function (FnParValor) provides the hability to work with a unlimmited number of parameters...

Example:

cParam = ''
cParam = cParam + 'MESS:Hasta la vista!;'
cParam = cParam + 'ROWPOS:5;'
cParam = cParam + 'COLPOS:10;'
cParam = cParam + 'COLOR:w/n;'

=fScreenOut(cParam)


FUNCTION fScreenOut
*-
PARAMETER cInParam
*-
PRIVATE cText, nRow, nCol, cColor
*-
cText = FnParValor(cInParam,'MESS' )
nRow = VAL( FnParValor(cInParam,'ROWPOS') )
nCol = VAL( FnParValor(cInParam,'COLPOS') )
cColor = FnParValor(cInParam,'COLOR' )
*-
*-- Defaults
*-
cText = IIF(EMPTY(cText),"WAIT",cText)
nRow = IIF(nRow=0,10,nRow)
nCol = IIF(nCol=0,37,nCol)
cColor = IIF(EMPTY(cColor),"W/N",cColor)
*-
....
....
....







The function:

*----------------------------------------------------------
*- Funcion: FnParValor
*--
*- Objeto: Funci¢n que manipula los parametros de tipo
*- extendido.
*-
*- Cabe aclarar que en los parametros extendidos
*- los datos pueden venir en cualquier orden.
*- (Ej. "BASE:TalBD;INDEX:TalIdx" ¢
*- "INDEX:TelIdx;BASE:TalBD")
*--
*- Parametros:
*- cTexto -> String. Por este par metro se pasa el string
*- completo.
*- cValor -> String. Se pasa el tipo de valor que se desea
*- obtener (Pej. "BASES"). Este dato se
*- debe pasar sin ningun tipo de
*- especial incluido, de ello se encarga
*- la funci¢n.
*- cIni -> String. Opcional, valor por defecto ":". Este
*- es el marcador que separa el parametro
*- del valor.
*- cFin -> String. Opcional, valor por defecto ";". Este
*- es el marcador que indica el final
*- del valor.
*--
*- Retorno:
*- Retorna el valor solicitado en mayusculas, de no haber
*- hallado el valor indicado returna un string nulo.
*-
*----------------------------------------------------------
*-
*---
FUNCTION FnParValor
*---
*----
PARAMETER cTexto, cValor, cIni, cFin
*-
PRIVATE cAuxT, cAuxP, nLargo, cRet, cProc, nAcum, lFinDo, ;
nParam, cAucO
*-
*-- Parametros
*-
nParam = PARAMETERS()
DO CASE
CASE nParam = 2
cIni = ":"
cFin = ";"
CASE nParam = 3
cFin = ";"
ENDCASE
*-
*-- Inicio de variables
*-
cAuxT = UPPER(ALLTRIM(cTexto))
nLargo = LEN(cAuxT)
cAuxP = UPPER(ALLTRIM(cValor))
cRet = ""
cProc = ""
nAcum = 0
lFinDo = .T.
*-
*-- Inicia proceso
*--
*--- Si los valores no son vacios continuar
*--
IF nLargo>0 .AND. .NOT. EMPTY(cAuxP)
*-
*-- Si existe el parametro requerido continuar
*-
IF cAuxP $ cAuxT
*-
*-- Elimino todo el string anterior al valor solicitado
*-
cProc = SUBSTR(cAuxT,AT(cAuxP+cIni,cAuxT)+LEN(cAuxP+cIni),LEN(cAuxT))
*-
*-- Busco el final del valor. Marcado con ";" o por Nulo
*-
cProc = cProc + IIF(RIGHT(cProc,1)=cFin,"",cFin)
nLargo = LEN(cProc)
*-
DO WHILE nAcum<nLargo .AND. lFinDo
*-
nAcum = nAcum + 1
IF .NOT. SUBSTR(cProc,nAcum,1)=cFin
cRet = cRet + SUBSTR(cProc,nAcum,1)
ELSE
lFinDo = .F.
ENDIF
*-
ENDDO
*-
ENDIF
ENDIF
*-
cRet = ALLTRIM(cRet)
*-
RETURN cRet
 
Very fine! Remember that there is an upper size limit to the string length when using this custom combination parameter. FoxPro allows a parameter to have up to 1024 characters (or very close to that size). This method will work as long as the total size does not exceed 1K.

You can pass the data by reference, though. For example, you can create a variable as shown here. Then pass the variable name to the subroutine, which could then parse the variable. In practice, it would probably be simpler to create memory variables or arrays that the subroutine would look at.
 
Yes. String lenght is limited so for so many parameter, I use ARRAY instead. And I access id with #DEFINE manifest constant.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top