Recomendado: la función general de ASP para determinar si el valor de la base de datos está vacío Debido a las diferentes propiedades de varios campos, los métodos para determinar si un campo está vacío también son diferentes. La siguiente es una función general, que evita el dolor del tipo de campo. 'Verificar una variable no es una función vacía isblank (byref tempvar)' de forma predeterminada, suponga que no está en blanco isblank = falso 'ahora verifique por variable t
Una colección de funciones útiles en el desarrollo de ASP es bastante útil, ¡por favor guárdela!
'********************************************
'Cortar contenido - dividido por línea
'********************************************
Funciones SplitLines (contenido de ByVal, ByVal ContentNums)
Dim ts, i, l
ContentNums = int (contentNums)
If isnull (contenido) entonces salga de la función
i = 1
TS = 0
Para i = 1 a Len (contenido)
l = lcase (Mid (contenido, i, 5))
Si l = <br/> entonces
TS = TS+1
Final si
l = lcase (Mid (contenido, i, 4))
Si l = <br> entonces
TS = TS+1
Final si
l = lcase (Mid (contenido, i, 3))
Si l = <p> entonces
TS = TS+1
Final si
Si ts> contentNums, entonces salga por
Próximo
Si ts> contentNums entonces
Contenido = izquierda (contenido, I-1)
Final si
Splitlines = contenido
Función final
'********************************************
'Cortar contenido - dividido por personaje
'********************************************
Función CUTSTR (BYVAL STR, BYVAL STRLEN)
Dim l, t, c, i
If isnull (str) entonces futstr =: Función de salida
l = len (str)
Strlen = int (strlen)
t = 0
Para i = 1 a l
C = ASC (Mid (Str, I, 1))
Si c <0 o c> 255 entonces t = t+2 más t = t+1
Si t> = strlen entonces
Cutstr = izquierda (str, i) ...
Salir
Demás
CUTST = STR
Final si
Próximo
Función final
'********************************************
'Eliminar la etiqueta de referencia
'********************************************
Función delquote (strContent)
If isnull (strContent) y luego salir de la función
Atenuar
Establecer re = nuevo regexp
re.ignorecase = True
re.global = verdadero
re.pattern =/[Quote /font>(.–^/font>*?)/–// QUOTE/]
strContent = re.replace (strContent,)
re.pattern =/[quote = (. [^/]]*)/] (. [^/]]*?)/[// quote/]]]*?)/[// quote/]
strContent = re.replace (strContent,)
Establecer re = nada
Delquote = strContent
Función final
'********************************************
'Obtener IP del cliente
'********************************************
función getip ()
Dim Strip, IP_ary, Strip_List
strip_list = reemplazar (request.serverVariables (http_x_forwarded_for), ',)
If instrer (strip_list ,,) <> 0 entonces
Ip_ary = split (strip_list ,,)
strip = ip_ary (0)
Demás
strip = strip_list
Final si
Si strip = vacía, entonces strip = reemplazar (request.serverVariables (remoto_addr), ',)
getip = Strip
Función final
Este artículo es recopilado y compilado por Design Home
'********************************************
'Obtenga información sobre el navegador de clientes
'********************************************
función getBrowser (strua)
Dim Arrinfo, Strtype, TEMP1, TEMP2
strtype =
strua = lcase (strua)
Arrinfo = Array (Unkown, Unkown)
'Juicio del navegador
if instrer (strua, mozilla)> 0 entonces arrinfo (0) = mozilla
if instrer (strua, icab)> 0 entonces Arrinfo (0) = icab
if Instr (strua, lynx)> 0 entonces Arrinfo (0) = Lynx
if instrer (strua, enlaces)> 0 entonces Arrinfo (0) = Links
if instr (strua, elinks)> 0 entonces Arrinfo (0) = Elinks
if instrer (strua, jbrowser)> 0 entonces Arrinfo (0) = jbrowser
if instrer (strua, konqueror)> 0 entonces Arrinfo (0) = Konqueror
if Instr (strua, wget)> 0 entonces Arrinfo (0) = wget
Si Instr (strua, pregúntale a Jeeves)> 0 o Instr (strua, teoma)> 0 entonces Arrinfo (0) = Pregunte Jeeves/Teoma
if Instr (strua, wget)> 0 entonces Arrinfo (0) = wget
if instrer (strua, ópera)> 0 entonces Arrinfo (0) = Opera
Si Instr (strua, gecko)> 0 entonces
strtype = [gecko]
Arrinfo (0) = Mozilla
if Instr (strua, aol)> 0 entonces Arrinfo (0) = AOL
if Instr (strua, netscape)> 0 entonces Arrinfo (0) = Netscape
if instr (strua, firefox)> 0 entonces Arrinfo (0) = Firefox
if instrer (strua, chimera)> 0 entonces Arrinfo (0) = Chimera
if Instr (strua, Camino)> 0 entonces Arrinfo (0) = Camineo
if instrer (strua, galeon)> 0 entonces Arrinfo (0) = Galeon
If Instr (Strua, K-Meleon)> 0 entonces Arrinfo (0) = K-Meleon
Arrinfo (0) = Arrinfo (0)+Strtype
final si
if Instr (strua, bot)> 0 o instr (strua, rastrear)> 0 entonces
strtype = [bot/rastreador]
Arrinfo (0) =
if Instr (strua, grub)> 0 entonces Arrinfo (0) = grub
if instrer (strua, googlebot)> 0 entonces Arrinfo (0) = GoogleBot
if instr (strua, msnbot)> 0 entonces arreRinfo (0) = msn bot
Si Instr (strua, slurp)> 0 entonces Arrinfo (0) = Yahoo! Sorber
Arrinfo (0) = Arrinfo (0)+Strtype
final si
if Instr (strua, AppleWebkit)> 0 entonces
strtype = [AppleWebkit]
Arrinfo (0) =
if instr (strua, omniweb)> 0 entonces Arrinfo (0) = OmniWeb
if instrer (strua, safari)> 0 entonces Arrinfo (0) = Safari
Arrinfo (0) = Arrinfo (0)+Strtype
final si
if instrer (strua, msie)> 0 entonces
strtype = [msie
temp1 = mid (strua, (instr (strua, msie) +4), 6)
TEMP2 = INSTR (TEMP1,;)
temp1 = izquierda (temp1, temp2-1)
strtype = strtype & temp1]
Arrinfo (0) = Internet Explorer
if instrer (strua, msn)> 0 entonces Arrinfo (0) = msn
if Instr (strua, aol)> 0 entonces Arrinfo (0) = AOL
if instrer (strua, webtv)> 0 entonces arreRInfo (0) = webTV
if Instr (strua, myie2)> 0 entonces Arrinfo (0) = myie2
if instrer (strua, maxthon)> 0 entonces Arrinfo (0) = maxthon
if Instr (strua, gosurf)> 0 entonces Arrinfo (0) = Gosurf
if instrer (strua, netcaptor)> 0 entonces Arrinfo (0) = netcaptor
if instr (strua, sleipnir)> 0 entonces arreRinfo (0) = Sleipnir
if Instr (strua, avant navegador)> 0 entonces Arrinfo (0) = AvantBrowser
if Instr (strua, greenbrowser)> 0 entonces Arrinfo (0) = Greenbrowser
if Instr (strua, Slimbrowser)> 0 entonces Arrinfo (0) = Slimbrowser
Arrinfo (0) = Arrinfo (0)+Strtype
final si
'Juicio del sistema operativo
if instrer (strua, windows)> 0 entonces Arrinfo (1) = Windows
if instrer (strua, windows ce)> 0 entonces Arrinfo (1) = Windows CE
If Instr (Strua, Windows 95)> 0 Entonces Arrinfo (1) = Windows 95
if Instr (strua, win98)> 0 entonces Arrinfo (1) = Windows 98
Si Instr (Strua, Windows 98)> 0 luego Arrinfo (1) = Windows 98
Si Instr (Strua, Windows 2000)> 0 luego Arrinfo (1) = Windows 2000
if instrer (strua, windows xp)> 0 entonces Arrinfo (1) = Windows XP
if instrer (strua, windows nt)> 0 entonces entonces
Arrinfo (1) = Windows NT
If Instr (Strua, Windows NT 5.0)> 0 Entonces Arrinfo (1) = Windows 2000
If Instr (Strua, Windows NT 5.1)> 0 entonces Arrinfo (1) = Windows XP
Si Instr (Strua, Windows NT 5.2)> 0 luego Arrinfo (1) = Windows 2003
final si
Si Instr (strua, x11)> 0 o Instr (strua, unix)> 0 entonces Arrinfo (1) = Unix
Si instrer (strua, sunos)> 0 o instr (strua, sun os)> 0 entonces arrinfo (1) = Sun OS
if Instr (strua, powerpc)> 0 o instr (strua, ppc)> 0 entonces arrinfo (1) = powerpc
if Instr (strua, Macintosh)> 0 entonces Arrinfo (1) = Mac
if Instr (strua, Mac OSX)> 0 entonces Arrinfo (1) = MACOSX
if Instr (strua, freeBSD)> 0 entonces Arrinfo (1) = FreeBSD
if instrer (strua, linux)> 0 entonces Arrinfo (1) = Linux
Si Instr (Strua, PalmSource)> 0 o Instr (Strua, Palmos)> 0 entonces Arrinfo (1) = Palmos
if Instr (strua, wap)> 0 entonces Arrinfo (1) = wap
'Arrinfo (0) = strua
getBrowser = Arrinfo
función final
'********************************************
'Calculando números aleatorios
'********************************************
función randomstr (intlength)
Dim Strseed, Seedlength, Pos, Str, I
strseed = abcdefghijklmnopqrstuvwxyz1234567890
longitud de semilla = len (strseed)
str =
Aleatorizar
para i = 1 a intlength
str = str+mid (strseed, int (seedlength*rnd) +1,1)
próximo
randomstr = str
función final
'********************************************
'Cerrado automáticamente UBB
'********************************************
función Closeubb (strContent)
Dim Arrtags, I, OpenPos, Closepos, RE, Strmatchs, J, Match
Establecer re = nuevo regexp
re.ignorecase = True
re.global = verdadero
ARRTAGS = Array (código, cita, lista, color, alineación, fuente, tamaño, b, i, u, html)
para i = 0 a Ubund (Arrtags)
OpenPos = 0
Closeepos = 0
re.pattern =/[+arrtags (i)+(= [^/[/]]+|)/]
Establecer strmatchs = re.execute (strContent)
Para cada partido en strmatchs
OpenPos = OpenPos+1
próximo
re.pattern =/[/+arrtags (i)+/]
Establecer strmatchs = re.execute (strContent)
Para cada partido en strmatchs
ClosePos = Closeepos+1
próximo
para j = 1 a OpenPos-Closepos
strContent = strContent+[/+arrtags (i)+]
próximo
próximo
Closeubb = strContent
función final
'********************************************
'Cierre automáticamente HTML
'********************************************
Función CloseHtml (strContent)
Dim Arrtags, I, OpenPos, Closepos, RE, Strmatchs, J, Match
Establecer re = nuevo regexp
re.ignorecase = True
re.global = verdadero
ARRTAGS = Array (P, Div, Span, Table, UL, Font, B, U, I, H1, H2, H3, H4, H5, H6)
para i = 0 a Ubund (Arrtags)
OpenPos = 0
Closeepos = 0
re.pattern =/<+arrtags (i)+([^/</>]+|)//
Establecer strmatchs = re.execute (strContent)
Para cada partido en strmatchs
OpenPos = OpenPos+1
próximo
re.pattern =/</+arrtags (i)+//>
Establecer strmatchs = re.execute (strContent)
Para cada partido en strmatchs
ClosePos = Closeepos+1
próximo
para j = 1 a OpenPos-Closepos
strContent = strContent+</+arrtags (i)+>
próximo
próximo
CloseHtml = strContent
función final
'********************************************
'Lea el archivo
'********************************************
Función loadFromFile (archivo byval)
Dim objstream
Dim rtext
Rtext = array (0,)
En el currículum de error siguiente
Establecer objstream = server.createObject (ADODB.Stream)
Si err entonces
Rtext = array (err.number, err.description)
LoadFromFile = rtext
Err.Clear
función de salida
Final si
Con objstream
.Type = 2
.Mode = 3
.Abierto
.Charset = UTF-8
.Position = objstream.size
.LoadFromFile Server.Mappath (archivo)
Si err.number <> 0 entonces
Rtext = array (err.number, err.description)
LoadFromFile = rtext
Err.Clear
función de salida
Final si
Rtext = array (0, .readText)
.Cerca
Terminar con
LoadFromFile = rtext
Establecer objstream = nada
Función final
'********************************************
'Guarde el archivo
'********************************************
Función savetofile (Byval strbody, archivo byval)
Dim objstream
Dim rtext
Rtext = array (0,)
En el currículum de error siguiente
Establecer objstream = server.createObject (ADODB.Stream)
Si err entonces
Rtext = array (err.number, err.description)
Err.Clear
función de salida
Final si
Con objstream
.Type = 2
.Abierto
.Charset = UTF-8
.Position = objstream.size
.WriteText = strbody
.Savetofile Server.Mappath (archivo), 2
.Cerca
Terminar con
Rtext = array (0, guarde el archivo correctamente!)
Savetofile = rtext
Establecer objstream = nada
Función final
'********************************************
'Operación de modificación de adición de dominio
'********************************************
función dbquest (tabla, dbarray, acción)
dim addcount, tempdb, i, v
if Action <> Insertar o Action <> Update y luego Action = insertar
if Action = Insertar entonces V = 2 más V = 3
Si no isArray (dbarray) entonces
DBQUEST = -1
función de salida
demás
Establecer tempdb = server.CreateObject (ADODB.RecordSet)
En el currículum de error siguiente
Tempdb.open Table, Conn, 1, V
Si err entonces
DBQUEST = -2
función de salida
final si
if Action = Insertar entonces tempdb.addnew
AddCount = Ubound (dBarray, 1)
para i = 0 para addcount
TEMPDB (DBARRAY (I) (0)) = DBArray (i) (1)
próximo
Tempdb.update
Tempdb.close
establecer tempdb = nada
DBQUEST = 0
final si
función final
'********************************************
'Verifique si los componentes del sistema están instalados
'********************************************
Función checkobjinstalled (strclassstring)
En el currículum de error siguiente
Temperatura oscura
Err = 0
Dim tmpobj
Establecer tmpobj = server.createObject (strclassstring)
Temp = err
Si temp = 0 o temp = -2147221477 entonces
CheckObJinstalled = True
Elseif temp = 1 o temp = -2147221005 entonces
CheckObJinstalled = falso
Final si
Err.Clear
Establecer tmpobj = nada
Err = 0
Función final
'********************************************
'Judge Server Microsoft.xmldom
'********************************************
Función getxmldom
En el currículum de error siguiente
Temperatura oscura
getxmldom = microsoft.xmldom
Err = 0
Dim tmpobj
Establecer tmpobj = server.createObject (getxmldom)
Temp = err
Si temp = 1 o temp = -2147221005 entonces
getxmldom = msxml2.domdocument.5.0
Final si
Err.Clear
Establecer tmpobj = nada
Err = 0
función final
'********************************************
'Judge Server msxml2.ServerXMLHTTP
'********************************************
Función getxmlhttp
En el currículum de error siguiente
Temperatura oscura
getxmlhttp = msxml2.serverxmlhttp
Err = 0
Dim tmpobj
Establecer tmpobj = server.createObject (getxmlhttp)
Temp = err
Si temp = 1 o temp = -2147221005 entonces
getxmlhttp = msxml2.serverxmlhttp.5.0
Final si
Err.Clear
Establecer tmpobj = nada
Err = 0
función final
'********************************************
'Filtrado de palabras clave de basura
'********************************************
función filterspam (str, ruta)
En el currículum de error siguiente
filterspam = falso
Dim spamxml, spamitem
Establecer spamxml = server.createObject (getxmldom)
Si err entonces
Err.Clear
función de salida
final si
spamxml.async = falso
spamxml.load (server.mappath (ruta))
Si spamxml.parseError.errrocode = 0 entonces
Para cada spamitem en spamxml.selectnodes (// clave)
if instrer (lcase (str), lcase (spamitem.text)) <> 0 entonces
filterspam = verdadero
función de salida
final si
próximo
final si
establecer spamxml = nada
función final
'**********************************************************************
'Propósito: verifique el formulario regular
'Enter: ID
'Return: el éxito es verdadero
'**********************************************************************
Función checkregexp (fuente, párr.
Si para = [nombre de usuario] entonces
para =^[. A-ZA-Z0-9/U4E00-/U9FA5]+
Final si
Si para = [contraseña] entonces
para =^[A-Z0-9]+
Final si
Si para = [correo electrónico] entonces
para =^([0-9-Za-z] ([-./W]*[0-9-Za-z])*@([0-9-Za-z] [-/w]*/.)+[A-Za-Z]*)
Final si
Si para = [página de inicio] entonces
para =^[A-Za-Z]+: // [A-Za-Z0-9 /-/./]+?/*
Final si
Si para = [nojapan] entonces
para = [/u3040-/u30ff]+
Final si
Si para = [GUID] entonces
para =^/w {8}/-/w {4}/-/w {4}/-/w {4}/-/w {4}/-/w {12}
Final si
Atenuar
Establecer re = nuevo regexp
re.global = verdadero
re.pattern = párrico
re.ignorecase = falso
Checkregexp = re.test (fuente)
Función final
'********************************************************
'Obtenga el número de personas en línea
'********************************************************
función getOnline
getOnline = 1
if len (aplicación (space_cookiename_onlinecount))> 0 entonces
Si datediff (s, aplicación (space_cookiename_useronlineCounttime), ahora ())> 60 entonces entonces
Application.lock ()
Aplicación (space_cookiename_online) = aplicación (space_cookiename_onlinecount)
Aplicación (space_cookiename_onlinecount) = 1
Aplicación (space_cookiename_onlinecountkey) = randstr (2)
Aplicación (space_cookiename_useronlineCounttime) = ahora ()
Application.unlock ()
demás
if session (space_cookienameUseronlinekey) <> aplicación (space_cookiename_onlinecountkey) entonces
Application.lock ()
Aplicación (space_cookiename_onlinecount) = aplicación (space_cookiename_onlinecount) +1
Application.unlock ()
Sesión (space_cookienameUseronlineKey) = aplicación (space_cookiename_onlinecountkey)
final si
final si
demás
Application.lock
Aplicación (space_cookiename_online) = 1
Aplicación (space_cookiename_onlinecount) = 1
Aplicación (space_cookiename_onlinecountkey) = randstr (2)
Aplicación (space_cookiename_useronlineCounttime) = ahora ()
Aplicación
final si
getOnline = aplicación (space_cookiename_online)
función final
%>
Este artículo es recopilado y compilado por Design Home
Compartir: ASP exporta datos de la base de datos a la tabla de Excel El código de instancia ASP exporta directamente los datos en la base de datos a la hoja de cálculo de Excel. !-#include file = ../conn.asp-- % dim s, sql, nombre de archivo, fs, myfile, x set fs = server.createObject (scripting.filesystemObject) '-Suponga que desea que el archivo de Excel generado se almacene de la siguiente manera.