funciones en ASP

30/04/2007 - 18:29 por Alberto Fuentes L. | Informe spam
Un saludo a todos los miembros de esta comunidad, como convierto un campo
caracter a valor, creo que puede ser:

mTotal=mTotal+VAL(campo)

No se que funcion usar para suprimir los espaciones en blanco del lado
derecho, ejemplo:

'20 '

y solo quede '20' yo uso una funcion llamada TRIM(),

alguien conoce alguna pagina donde pueda ver funciones para convertir texto
a numero o viceversa, o donde puedo ver todas las funciones que opera el
ASP?

Sin mas por el momento y en espera de sus comentarios, quedo de ustedes.

Alberto Fuentes L.


________________________________________________________________________
<hr>
Siconet, S.A. de C.V.
Ixtepete # 2064, Pinar de la Calma
siconet@siconet.com.mx
http://www.siconet.com.mx

Preguntas similare

Leer las respuestas

#6 Nuno Santos
04/05/2007 - 12:09 | Informe spam
Holá ALberto,
No necessitas de repetir la consulta en cada Orden... para tal lo que
debes hacer es alterar unicamente la parte del orden y mantener la consulta
igual...

SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b
on
a.canal = b.numero Where Len(a.codigo)>0 "

if mOrd = 0 Then
SQL = SQL & " ORDER BY Giro, Nombre"
else if mOrd = 1 then
SQL = SQL & " ORDER BY ???, Nombre"
else if mOrd = 2 then
SQL = SQL & " ORDER BY ???, Nombre"
else
SQL = SQL & " ORDER BY ???, Nombre"
end if

Nuno Santos

"Alberto Fuentes L." wrote in message
news:
Bien por fin ya pude, en este link puedes observar mi primer ASP, en
consultar una tabla o barrer el contenido de ella

http://siconet.myvnc.com/asp/bdcons...p?oOrden=0

mmm puede que para algunos sea algo sencillo, pero para su servidor fue un
reto hacerlo, paso el codigo por sí alguien le sirve o lo modifique, como
yo lo hice, segun mis necesidades (me faltaria hacer la paginacion):

<%@ LANGUAGE="VBScript" %>
<%
'==> 'Ejemplos de Base de Datos Carlos de la Orden Dijs
www.aspfacil.com -- Mar/01
'==> Dim oConn, rs, SQL
Dim nombre
Dim mOrd

mOrd = Request.QueryString("oOrden")
'Creo el objeto Connection
set oConn = Server.CreateObject("ADODB.Connection")
'Para conectar a la base de datos, utiliza una de estas conexiones
'Solo tienes que quitar el comentario (') a la que quieras utilizar
'y comentar o borrar las otras líneas

'Access con OLEDB:
'oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("base.mdb")
'Access con ODBC:
'oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("base.mdb")
oConn.Open "Driver={SQL
Server};server=SEVIDOR_SQL;databaseÚTABASE;uid=USER;pwd=PASSWORD;"

'En mi caso, tengo la cadena de conexión en una variable de aplicación
'oConn.Open Application("CadenaConn")
'Para utilizar esta, tienes que tener un fichero GLOBAL.ASA con esta línea
' Application("CadenaConn") = ... la cadena de conexión que quieras
'En el Sub Application_OnStart

'Mi sentencia SQL que extrae todos los campos de la tabla 'TablaEjemplo'

if mOrd = "0" then 'Ordenar por Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by a.nombre"
end if

if mOrd = "1" then 'Ordenar por Ciudad y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by a.ciudad,a.nombre"
end if

if mOrd = "2" then 'Ordenar por Giro y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by giro,a.nombre"
end if

if mOrd = "3" then 'Ordenar por Version y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by
a.observa,a.codigo,a.nombre"
end if

'SQL="SELECT fecha,mani AS viaje ,producto,rcajas,vcajas+acajas as
ventas,merma,rcajas-vcajas-acajas-merma as saldo,cuenp,prove FROM viajes
ORDER BY cuenp,mani"
'SQL="SELECT fecha,mani,producto,rcajas,vcajas+acajas as
ventas,merma,rcajas-vcajas-acajas-merma as saldo,cuenp,prove FROM viajes
WHERE LEFT(cuenp,6) = " & mCta & " ORDER BY cuenp,mani"
'Creo un Recordset (set rs) a partir de la ejecución de la consulta
(oConn.Execute)
set rs = oConn.Execute(SQL)
'¿Esta vacío?
if rs.EOF then
Response.Write("No hay ningún registro en esta tabla")
else
'Llamo al procedimiento que pinta la tabla
PintarTabla
end if

'Cierro el Recordset
rs.Close
'Destruyo el objeto
set rs = nothing
'Cierro la conexión
oConn.Close
'Destruyo la conexión
set oConn = nothing

'> Sub PintarTabla ()

Dim mEmp,mUsers,mUserSql
mEmp = 0
mUsers = 0
mUserSql = 0

'Utiliza el objeto rs abierto
'para pintar la tabla

'La primera fila la escribo directamente, con
'los nombres de los campos
'Response.Write( "<p align=""CENTERT""><b>Listado de Viajes por Productor#
" & mCta & "</B></p>" )
Response.Write( "<html>" & vbCrlf)
Response.Write( "<body background='../images/logosico.jpg'>" & vbCrlf)

Response.Write( "<TABLE BORDER=""1"">" & vbCrlf)
Response.Write( "<TR>" & vbCrlf)
For i = 0 to RS.Fields.Count - 1
If i <3 Then
Response.Write("<TH bgcolor='#d3d3d3'><a
href='http://siconet.myvnc.com/asp/bdcons...den=" & i & "'
title='Ordenar por " & RS(i).Name & "'>" & RS(i).Name & "</a></TH>" &
vbCrlf )
else
If i=3 Then
Response.Write("<TH colspan='2' bgcolor='#d3d3d3'><a
href='http://siconet.myvnc.com/asp/bdcons...p?oOrden=3'
title='Ordenar por Versi&oacute;n del Siconet DBF o SQL'>VERSION</a></TH>"
& vbCrlf )
End if
end if
Next
Response.Write( "</TR>" & vbCrlf)

'Hasta que llegue al final del recordset...
while not rs.EOF
' IF rs.Fields("saldo") = "0" Then
'Imprimo una fila de la tabla
'para cada registro que encuentre
Response.Write( "<TR>" & vbCrlf )
For i = 0 to RS.Fields.Count - 1
If i<3 Then
Response.Write("<TD>" & RS(i) & "</TD>" & vbCrlf )
Else
If i=3 Then
Response.Write("<TD colspan='2'>" & RS(i) & RS(i+1) & "</TD>" &
vbCrlf )
End If
End If
Next

Response.Write( "</TR>" & vbCrlf )
mEmp = mEmp + 1
IF NOT IsEmpty(RS(3)) Then
IF Instr(RS(4),"SQL")>0 Then
mUserSql = mUserSql + CInt(RS(3))
Else
mUsers = mUsers + CInt(RS(3))
End If
END IF
'mTMerma = mTMerma + rs.Fields("codigo")
'MUY IMPORTANTE!!!!!
'Pasamos al siguiente registro
' End If
rs.MoveNext
'Olvidarte esto significa que vas a imprimir
'siempre el mismo registro... Un bucle infinito!
wend
'Cierro la tabla

Response.Write("<TH align='right' bgcolor='#CCCCCC'>Total de
Empresas</TH>" & vbCrlf )
Response.Write("<TH align='right' bgcolor='#CCCCCC'>" & mEmp & "</TH>" &
vbCrlf )
Response.Write("<TH align='right' bgcolor='#CCCCCC'>Total de
Usuarios</TH>" & vbCrlf )
Response.Write("<TH colspan='2' align='right' bgcolor='#CCCCCC'>DBF: " &
FormatNumber(mUsers,0) & "<br>SQL: " & FormatNumber(mUserSql,0) &
"<br>-" & "<br>Total: " &FormatNumber(mUsers+mUserSql,0) &
"</TH>" & vbCrlf )

Response.Write("</TABLE>")
Response.Write( "</body>" & vbCrlf)
Response.Write( "</html>" & vbCrlf)

End Sub 'PintarTabla
%>

________________________________________________________________________
<hr>
Siconet, S.A. de C.V.
Ixtepete # 2064, Pinar de la Calma

http://www.siconet.com.mx
"Manuel Vera" escribió en el mensaje
news:u0OE$
Hola

Tienes las siguientes:

CLng("entero_largo") = valor mayor a 32200 + o -
CInt("entero") = valor menor a 32200 + o -
CDbl("double") = maneja mas decimales que single
CSng("single")

FormatNumber(
Expression
[,NumDigitsAfterDecimal
[,IncludeLeadingDigit
[,UseParensForNegativeNumbers
[,GroupDigits]]]])

* Expression
Required. Expression to be formatted.

* NumDigitsAfterDecimal
Optional. Numeric value indicating how many places to the right of the
decimal are displayed. Default value is -1, which indicates that the
computer's regional settings are used.

* IncludeLeadingDigit
Optional. Tristate constant that indicates whether or not a leading zero
is displayed for fractional values. See Settings section for values.

* UseParensForNegativeNumbers
Optional. Tristate constant that indicates whether or not to place
negative values within parentheses. See Settings section for values.

* GroupDigits
Optional. Tristate constant that indicates whether or not numbers are
grouped using the group delimiter specified in the control panel. See
Settings section for values.

The following example uses the FormatNumber function to format a number
to have four decimal places:
Function FormatNumberDemo
Dim MyAngle, MySecant, MyNumber
MyAngle = 1.3 ' Define angle in radians.
MySecant = 1 / Cos(MyAngle) ' Calculate secant.
FormatNumberDemo = FormatNumber(MySecant,4) ' Format MySecant to four
decimal places.
End Function

Salu2
MV

"Alberto Fuentes L." escribió en el mensaje
news:
Gracias Manuel, ya le di click a las paginas, pero me perdi, realmente
no supe a donde ir de tanta opciones, solo deseo saber como puedo
convertir un campo tipo caracter en valor, cual es la funcion???.

Y no recuerdo si para darle formato a un numero es FORMATNUMBER.

Saludos.

Alberto Fuentes








Respuesta Responder a este mensaje
#7 Alberto Fuentes L.
07/05/2007 - 20:29 | Informe spam
Si tienes razon Nuno, como que me dormi.

Existe en ASP el Commando

Do Case
Case mOrden= 0

EndCase

Saludos

________________________________________________________________________
<hr>
Siconet, S.A. de C.V.
Ixtepete # 2064, Pinar de la Calma

http://www.siconet.com.mx
"Nuno Santos" <nunos7@[REMOVER]hotmail.com> escribió en el mensaje
news:%
Holá ALberto,
No necessitas de repetir la consulta en cada Orden... para tal lo que
debes hacer es alterar unicamente la parte del orden y mantener la
consulta igual...

SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b
on
a.canal = b.numero Where Len(a.codigo)>0 "

if mOrd = 0 Then
SQL = SQL & " ORDER BY Giro, Nombre"
else if mOrd = 1 then
SQL = SQL & " ORDER BY ???, Nombre"
else if mOrd = 2 then
SQL = SQL & " ORDER BY ???, Nombre"
else
SQL = SQL & " ORDER BY ???, Nombre"
end if

Nuno Santos

"Alberto Fuentes L." wrote in message
news:
Bien por fin ya pude, en este link puedes observar mi primer ASP, en
consultar una tabla o barrer el contenido de ella

http://siconet.myvnc.com/asp/bdcons...p?oOrden=0

mmm puede que para algunos sea algo sencillo, pero para su servidor fue
un reto hacerlo, paso el codigo por sí alguien le sirve o lo modifique,
como yo lo hice, segun mis necesidades (me faltaria hacer la paginacion):

<%@ LANGUAGE="VBScript" %>
<%
'==>> 'Ejemplos de Base de Datos Carlos de la Orden Dijs
www.aspfacil.com -- Mar/01
'==>> Dim oConn, rs, SQL
Dim nombre
Dim mOrd

mOrd = Request.QueryString("oOrden")
'Creo el objeto Connection
set oConn = Server.CreateObject("ADODB.Connection")
'Para conectar a la base de datos, utiliza una de estas conexiones
'Solo tienes que quitar el comentario (') a la que quieras utilizar
'y comentar o borrar las otras líneas

'Access con OLEDB:
'oConn.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &
Server.MapPath("base.mdb")
'Access con ODBC:
'oConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" &
Server.MapPath("base.mdb")
oConn.Open "Driver={SQL
Server};server=SEVIDOR_SQL;databaseÚTABASE;uid=USER;pwd=PASSWORD;"

'En mi caso, tengo la cadena de conexión en una variable de aplicación
'oConn.Open Application("CadenaConn")
'Para utilizar esta, tienes que tener un fichero GLOBAL.ASA con esta
línea
' Application("CadenaConn") = ... la cadena de conexión que quieras
'En el Sub Application_OnStart

'Mi sentencia SQL que extrae todos los campos de la tabla 'TablaEjemplo'

if mOrd = "0" then 'Ordenar por Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by a.nombre"
end if

if mOrd = "1" then 'Ordenar por Ciudad y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by a.ciudad,a.nombre"
end if

if mOrd = "2" then 'Ordenar por Giro y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by giro,a.nombre"
end if

if mOrd = "3" then 'Ordenar por Version y Nombre
SQL="SELECT a.nombre AS EMPRESA,a.ciudad AS CIUDAD,b.descrip as
GIRO,a.codigo,a.observa AS VERSION FROM CLIENTES a inner join canal b on
a.canal = b.numero Where Len(a.codigo)>0 ORDER by
a.observa,a.codigo,a.nombre"
end if

'SQL="SELECT fecha,mani AS viaje ,producto,rcajas,vcajas+acajas as
ventas,merma,rcajas-vcajas-acajas-merma as saldo,cuenp,prove FROM viajes
ORDER BY cuenp,mani"
'SQL="SELECT fecha,mani,producto,rcajas,vcajas+acajas as
ventas,merma,rcajas-vcajas-acajas-merma as saldo,cuenp,prove FROM viajes
WHERE LEFT(cuenp,6) = " & mCta & " ORDER BY cuenp,mani"
'Creo un Recordset (set rs) a partir de la ejecución de la consulta
(oConn.Execute)
set rs = oConn.Execute(SQL)
'¿Esta vacío?
if rs.EOF then
Response.Write("No hay ningún registro en esta tabla")
else
'Llamo al procedimiento que pinta la tabla
PintarTabla
end if

'Cierro el Recordset
rs.Close
'Destruyo el objeto
set rs = nothing
'Cierro la conexión
oConn.Close
'Destruyo la conexión
set oConn = nothing

'>> Sub PintarTabla ()

Dim mEmp,mUsers,mUserSql
mEmp = 0
mUsers = 0
mUserSql = 0

'Utiliza el objeto rs abierto
'para pintar la tabla

'La primera fila la escribo directamente, con
'los nombres de los campos
'Response.Write( "<p align=""CENTERT""><b>Listado de Viajes por
Productor# " & mCta & "</B></p>" )
Response.Write( "<html>" & vbCrlf)
Response.Write( "<body background='../images/logosico.jpg'>" & vbCrlf)

Response.Write( "<TABLE BORDER=""1"">" & vbCrlf)
Response.Write( "<TR>" & vbCrlf)
For i = 0 to RS.Fields.Count - 1
If i <3 Then
Response.Write("<TH bgcolor='#d3d3d3'><a
href='http://siconet.myvnc.com/asp/bdcons...den=" & i & "'
title='Ordenar por " & RS(i).Name & "'>" & RS(i).Name & "</a></TH>" &
vbCrlf )
else
If i=3 Then
Response.Write("<TH colspan='2' bgcolor='#d3d3d3'><a
href='http://siconet.myvnc.com/asp/bdcons...p?oOrden=3'
title='Ordenar por Versi&oacute;n del Siconet DBF o
SQL'>VERSION</a></TH>" & vbCrlf )
End if
end if
Next
Response.Write( "</TR>" & vbCrlf)

'Hasta que llegue al final del recordset...
while not rs.EOF
' IF rs.Fields("saldo") = "0" Then
'Imprimo una fila de la tabla
'para cada registro que encuentre
Response.Write( "<TR>" & vbCrlf )
For i = 0 to RS.Fields.Count - 1
If i<3 Then
Response.Write("<TD>" & RS(i) & "</TD>" & vbCrlf )
Else
If i=3 Then
Response.Write("<TD colspan='2'>" & RS(i) & RS(i+1) & "</TD>" &
vbCrlf )
End If
End If
Next

Response.Write( "</TR>" & vbCrlf )
mEmp = mEmp + 1
IF NOT IsEmpty(RS(3)) Then
IF Instr(RS(4),"SQL")>0 Then
mUserSql = mUserSql + CInt(RS(3))
Else
mUsers = mUsers + CInt(RS(3))
End If
END IF
'mTMerma = mTMerma + rs.Fields("codigo")
'MUY IMPORTANTE!!!!!
'Pasamos al siguiente registro
' End If
rs.MoveNext
'Olvidarte esto significa que vas a imprimir
'siempre el mismo registro... Un bucle infinito!
wend
'Cierro la tabla

Response.Write("<TH align='right' bgcolor='#CCCCCC'>Total de
Empresas</TH>" & vbCrlf )
Response.Write("<TH align='right' bgcolor='#CCCCCC'>" & mEmp & "</TH>" &
vbCrlf )
Response.Write("<TH align='right' bgcolor='#CCCCCC'>Total de
Usuarios</TH>" & vbCrlf )
Response.Write("<TH colspan='2' align='right' bgcolor='#CCCCCC'>DBF: " &
FormatNumber(mUsers,0) & "<br>SQL: " & FormatNumber(mUserSql,0) &
"<br>-" & "<br>Total: " &FormatNumber(mUsers+mUserSql,0) &
"</TH>" & vbCrlf )

Response.Write("</TABLE>")
Response.Write( "</body>" & vbCrlf)
Response.Write( "</html>" & vbCrlf)

End Sub 'PintarTabla
%>

________________________________________________________________________
<hr>
Siconet, S.A. de C.V.
Ixtepete # 2064, Pinar de la Calma

http://www.siconet.com.mx
"Manuel Vera" escribió en el mensaje
news:u0OE$
Hola

Tienes las siguientes:

CLng("entero_largo") = valor mayor a 32200 + o -
CInt("entero") = valor menor a 32200 + o -
CDbl("double") = maneja mas decimales que single
CSng("single")

FormatNumber(
Expression
[,NumDigitsAfterDecimal
[,IncludeLeadingDigit
[,UseParensForNegativeNumbers
[,GroupDigits]]]])

* Expression
Required. Expression to be formatted.

* NumDigitsAfterDecimal
Optional. Numeric value indicating how many places to the right of the
decimal are displayed. Default value is -1, which indicates that the
computer's regional settings are used.

* IncludeLeadingDigit
Optional. Tristate constant that indicates whether or not a leading zero
is displayed for fractional values. See Settings section for values.

* UseParensForNegativeNumbers
Optional. Tristate constant that indicates whether or not to place
negative values within parentheses. See Settings section for values.

* GroupDigits
Optional. Tristate constant that indicates whether or not numbers are
grouped using the group delimiter specified in the control panel. See
Settings section for values.

The following example uses the FormatNumber function to format a number
to have four decimal places:
Function FormatNumberDemo
Dim MyAngle, MySecant, MyNumber
MyAngle = 1.3 ' Define angle in radians.
MySecant = 1 / Cos(MyAngle) ' Calculate secant.
FormatNumberDemo = FormatNumber(MySecant,4) ' Format MySecant to four
decimal places.
End Function

Salu2
MV

"Alberto Fuentes L." escribió en el mensaje
news:
Gracias Manuel, ya le di click a las paginas, pero me perdi, realmente
no supe a donde ir de tanta opciones, solo deseo saber como puedo
convertir un campo tipo caracter en valor, cual es la funcion???.

Y no recuerdo si para darle formato a un numero es FORMATNUMBER.

Saludos.

Alberto Fuentes












email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una pregunta AnteriorRespuesta Tengo una respuesta
Search Busqueda sugerida