Pega informações sobre o browser do usuário.
Exemplo:
var b = new BrowserInfo();
alert(b.version);
function BrowserInfo()
{
this.name = navigator.appName;
this.codename = navigator.appCodeName;
this.version = navigator.appVersion.substring(0,4);
this.platform = navigator.platform;
this.javaEnabled = navigator.javaEnabled();
this.screenWidth = screen.width;
this.screenHeight = screen.height;
}
Este blog é originalmente para ser um banco de funções e procedimentos públicas de qualquer linguagem, como a minha especialidade é liguagens Microsoft® vou me ater a elas, mas caso haja pessoas interessadas em passar funções ou procedimentos de outras linguagens, sintam-se a vontade para envia-las a mim.
quinta-feira, 27 de dezembro de 2007
quarta-feira, 26 de dezembro de 2007
NumberFormat()
Formata um número para SQL
Function NumberFormat(ByVal sExpr)
sExpr = sExpr & ""
If ereg("^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$", sExpr) Then
sExpr = CDbl(CDate(sExpr)) & ""
ElseIf Not IsNumeric(sExpr) Then
NumberFormat = "0"
Exit Function
End If
sExpr = Replace(sExpr, ",", ".")
NumberFormat = sExpr
End Function
Function NumberFormat(ByVal sExpr)
sExpr = sExpr & ""
If ereg("^[0-9]{1,2}/[0-9]{1,2}/[0-9]{4}$", sExpr) Then
sExpr = CDbl(CDate(sExpr)) & ""
ElseIf Not IsNumeric(sExpr) Then
NumberFormat = "0"
Exit Function
End If
sExpr = Replace(sExpr, ",", ".")
NumberFormat = sExpr
End Function
quarta-feira, 19 de dezembro de 2007
MapRoot()
Mapeia o caminho relativo para a raiz do site a partir da pasta atual.
Function MapRoot()
Dim MyPath, MyRoot
Dim MyArray
Dim i, j
MyPath = AspSelf()
MyRoot = ""
MyArray = Split(MyPath, "/")
j = UBound(MyArray) - 2
For i = j To 0 Step -1
MyRoot = MyRoot & "../"
Next
MapRoot = MyRoot
End Function
Function MapRoot()
Dim MyPath, MyRoot
Dim MyArray
Dim i, j
MyPath = AspSelf()
MyRoot = ""
MyArray = Split(MyPath, "/")
j = UBound(MyArray) - 2
For i = j To 0 Step -1
MyRoot = MyRoot & "../"
Next
MapRoot = MyRoot
End Function
quinta-feira, 13 de dezembro de 2007
Hex2Int()
Converte uma string hexadecimal em número
Function Hex2Int(ByVal hStr)
If Not eregi("^[a-f0-9]*$", hStr) Then
Err.Raise 1002, "ASP Util Library", "Hex2Int: Invalid argument: " & hStr
End If
Dim h, D, i
Dim c, ln
h = 0
ln = Len(hStr)
Set D = Server.CreateObject("Scripting.Dictionary")
For i = 0 To 9
D.Add i & "", i
Next
For i = 65 To 70
D.Add Chr(i), i - 55
Next
For i = ln To 1 Step -1
c = UCase(Mid(hStr, i, 1))
h = h + ( D(c) * ( 16 ^ (ln - i) ) )
Next
Set D = Nothing
Hex2Int = h
End Function
Function Hex2Int(ByVal hStr)
If Not eregi("^[a-f0-9]*$", hStr) Then
Err.Raise 1002, "ASP Util Library", "Hex2Int: Invalid argument: " & hStr
End If
Dim h, D, i
Dim c, ln
h = 0
ln = Len(hStr)
Set D = Server.CreateObject("Scripting.Dictionary")
For i = 0 To 9
D.Add i & "", i
Next
For i = 65 To 70
D.Add Chr(i), i - 55
Next
For i = ln To 1 Step -1
c = UCase(Mid(hStr, i, 1))
h = h + ( D(c) * ( 16 ^ (ln - i) ) )
Next
Set D = Nothing
Hex2Int = h
End Function
terça-feira, 11 de dezembro de 2007
GetRelativePath()
Mapeia o caminho relativo para um arquivo a partir da pasta atual.
Function GetRelativePath(ByVal FileName)
On Error Resume Next
If Mid(FileName, 2, 1) <> ":" Then
FileName = Server.MapPath(FileName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim a, b, a1, b1
Dim i, Str, j
a = Server.MapPath(AspSelf())
b = FileName
a = Split(a, "\")
b = Split(b, "\")
a1 = UBound(a)
b1 = UBound(b)
i = 0
Str = ""
Do While i <= a1 And i <= b1
If LCase(a(i)) <> LCase(b(i)) Then
For j = 0 To a1 - i - 1
Str = Str & "../"
Next
For j = i To b1
Str = Str & b(j)
If j <> b1 Then Str = Str & "/"
Next
GetRelativePath = Str
Exit Function
End If
i = i + 1
Loop
While i <= b1
Str = Str & b(i)
If i < str =" Str">
i = i + 1
Wend
If Str = "" Then Str = a(a1)
GetRelativePath = Str
End Function
Function GetRelativePath(ByVal FileName)
On Error Resume Next
If Mid(FileName, 2, 1) <> ":" Then
FileName = Server.MapPath(FileName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim a, b, a1, b1
Dim i, Str, j
a = Server.MapPath(AspSelf())
b = FileName
a = Split(a, "\")
b = Split(b, "\")
a1 = UBound(a)
b1 = UBound(b)
i = 0
Str = ""
Do While i <= a1 And i <= b1
If LCase(a(i)) <> LCase(b(i)) Then
For j = 0 To a1 - i - 1
Str = Str & "../"
Next
For j = i To b1
Str = Str & b(j)
If j <> b1 Then Str = Str & "/"
Next
GetRelativePath = Str
Exit Function
End If
i = i + 1
Loop
While i <= b1
Str = Str & b(i)
If i < str =" Str">
i = i + 1
Wend
If Str = "" Then Str = a(a1)
GetRelativePath = Str
End Function
sexta-feira, 7 de dezembro de 2007
GetFolder()
Obtém uma pasta e retorna um objeto Folder.
O FolderName pode ser um caminho absoluto e relativo.
Function GetFolder(ByVal FolderName)
On Error Resume Next
If Mid(FolderName, 2, 1) <> ":" Then
FolderName = Server.MapPath(FolderName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set GetFolder = FSO.GetFolder(FolderName)
If Err Then
Err.Clear
Set GetFolder = Nothing
End If
On Error GoTo 0
Set FSO = Nothing
End Function
O FolderName pode ser um caminho absoluto e relativo.
Function GetFolder(ByVal FolderName)
On Error Resume Next
If Mid(FolderName, 2, 1) <> ":" Then
FolderName = Server.MapPath(FolderName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim FSO
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set GetFolder = FSO.GetFolder(FolderName)
If Err Then
Err.Clear
Set GetFolder = Nothing
End If
On Error GoTo 0
Set FSO = Nothing
End Function
quarta-feira, 5 de dezembro de 2007
GetFileProps()
Obtém as propriedades de um arquivo e retorna
um objeto dicionário. Não esquecer de liberar o objeto depois de usá-lo.
Function GetFileProps(ByVal FileName)
On Error Resume Next
If Mid(FileName, 2, 1) <> ":" Then
FileName = Server.MapPath(FileName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim FSO, F, D
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set F = FSO.GetFile(FileName)
If Err Then
Err.Clear
Set FSO = Nothing
FileStats = Null
On Error GoTo 0
Exit Function
End If
On Error GoTo 0
Set D = Server.CreateObject("Scripting.Dictionary")
D.Add "DateCreated", F.DateCreated
D.Add "DateLastAccessed", F.DateLastAccessed
D.Add "DateLastModified", F.DateLastModified
D.Add "Size", F.Size
D.Add "Name", F.Name
Set F = Nothing
Set FSO = Nothing
Set GetFileProps = D
Set D = Nothing
End Function
um objeto dicionário. Não esquecer de liberar o objeto depois de usá-lo.
Function GetFileProps(ByVal FileName)
On Error Resume Next
If Mid(FileName, 2, 1) <> ":" Then
FileName = Server.MapPath(FileName)
End If
If Err Then Err.Clear
On Error GoTo 0
Dim FSO, F, D
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set F = FSO.GetFile(FileName)
If Err Then
Err.Clear
Set FSO = Nothing
FileStats = Null
On Error GoTo 0
Exit Function
End If
On Error GoTo 0
Set D = Server.CreateObject("Scripting.Dictionary")
D.Add "DateCreated", F.DateCreated
D.Add "DateLastAccessed", F.DateLastAccessed
D.Add "DateLastModified", F.DateLastModified
D.Add "Size", F.Size
D.Add "Name", F.Name
Set F = Nothing
Set FSO = Nothing
Set GetFileProps = D
Set D = Nothing
End Function
Assinar:
Postagens (Atom)