Ver Mensaje Individual
  #93 (permalink)  
Antiguo 29/03/2006, 08:50
Avatar de Muzztein
Muzztein
 
Fecha de Ingreso: agosto-2002
Ubicación: Hangar 18
Mensajes: 1.703
Antigüedad: 21 años, 8 meses
Puntos: 16
Funcion super util


Código HTML:
<%
REM INC_FUNCIONES_FORMATO.ASP 
REM VERSION 1.0
REM 20030328
REM formatea(entrada,formato_esperado,valor_por_defecto,arreglo_de_parseos)
REM ENTRADA Contiene la variable a formatear
REM FORMATO_ESPERADO Indica el formato en el que deberia venir la variable
REM VALOR_POR_DEFECTO En caso de que la variable no cumpla el formato, asigna este valor
REM ARREGLO_DE_PARSEOS Contiene un string separado por comas que contiene las tranformaciones deseadas a una misma variable.
REM EJEMPLO DE EJECUCCION: FORMATEA("holas",3,false,"1,0,4,6,10,13")

REM FORMATO ESPERADO 1 NUMERICO
REM FORMATO ESPERADO 2 FECHA
REM FORMATO ESPERADO 3 CADENA

REM Parseo  0  FIX COMILLAS SIMPLES
REM Parseo  1  FIX TAG HTML 
REM Parseo  2  FIX PUNTOS Y COMA EXEL
REM Parseo  3  FIX SQL INJECTION
REM Parseo  4  FIX BLANK SPACE / UNDERSCORE						
REM Parseo  5  TRANSFORMACION CSNG
REM Parseo  6  TRANSFORMACION CINT
REM Parseo  7  TRANSFORMACION Cdate
REM Parseo  8  TRANSFORMACION trim
REM Parseo  9  TRANSFORMACION lcase
REM Parseo  10 TRANSFORMACION ucase
REM Parseo  11 TRANSFORMACION CSTR
REM Parseo  12 TRANSFORMACION CDBL
REM Parseo  13 ENCOMILLADO
REM Parseo  14 DESCOMILLADO

function checa_formato_xp(entrada,formato)
	on error resume next
	err.Clear ()
	checa_formato_xp = false
	Select Case formato
	    Case 1
			if isnumeric(entrada) = true then 
				checa_formato_xp  = true
			end if
	    Case 2
			if isdate(entrada)   = true then 
				checa_formato_xp = true
			end if
	    Case 3
  			if len(entrada) <> 0   then 
				checa_formato_xp = true
			end if
	    Case Else 
				checa_formato_xp = true
	End Select
	if err.number <> 0 then	
		err.Clear ()
		checa_formato_xp = false
	end if	
end function


function fix_multiple_xp(cadena,parseo)
	on error resume next
	err.Clear ()
	dim aux 
	aux = cadena
	Select Case parseo
	    Case 0 ' FIX COMILLAS SIMPLES
			aux = replace(aux,"'","''")
	    Case 1 ' FIX TAG HTML 
			aux = replace(aux,"<","&lt;")
			aux = replace(aux,">","&gt;")
	    Case 2 ' FIX PUNTOS Y COMA EXEL
			aux = replace(aux,";","")
		Case 3 ' FIX SQL INJECTION
			aux = replace(aux,"--","")
			aux = replace(aux,"'","")
			aux = replace(aux,"=","")			
			aux = replace(aux,"&","")
		Case 4 'FIX BLANK SPACE / UNDERSCORE						
			aux = replace(trim(aux)," ","_")
		Case 5 'TRANSFORMACION CSNG
			aux = csng(aux)
		Case 6 'TRANSFORMACION CINT
			aux = cint(aux)
		Case 7 'TRANSFORMACION Cdate
			aux = cdate(aux)
		Case 8 'TRANSFORMACION trim
			aux = trim(aux)
		Case 9 'TRANSFORMACION lcase
			aux = lcase(aux)
		Case 10 'TRANSFORMACION ucase
			aux = ucase(aux)
		Case 11 'TRANSFORMACION CSTR
			aux = cstr(aux)
		Case 12 'TRANSFORMACION CDBL
			aux = cdbl(aux)
		Case 13 'ENCOMILLADO
			aux = "'" & aux & "'"
		Case 14 'DESCOMILLADO
			aux = replace(aux,"'","")			
	    Case Else 
			aux = aux
	End Select
	if err.number <> 0 then	
		err.Clear ()
		fix_multiple_xp = cadena
	else		
		fix_multiple_xp = aux
	end if	
end function	


function formatea(entrada,formato_esperado,valor_por_defecto,arreglo_de_parseos)
	on error resume next
	dim salida
	DIM arreglo
	formatea = valor_por_defecto
	salida	 = entrada
	if checa_formato_xp(salida,formato_esperado) = false then 
		exit function
	end if
	if arreglo_de_parseos <> false then 
		arreglo = split(arreglo_de_parseos,",")
		for y = 0 to ubound(arreglo)
		salida = fix_multiple_xp(salida,cint(arreglo(y)))
		next
	end if 
	if err.number <> 0 then 
		err.Clear ()
		exit function
	else
		formatea = salida
	end if
end function
%>