Some Functions from my personal ASP library;
File Exist v1.2
Code:
'***P13 ? File Exist v1.2 by Ferruh Mavituna
'//NFO//
' Check server for a file
'//ARGUMENTS//
' filename: Price (numeric)
'//RETURN//
' True / False
'//SAMPLE//
' If P13_FileExist("imgs/xx.jpg") Then Response.write "<img src=""imgs/xx.jpg"">"
Function P13_FileExist(byval filename)
If filename <> "" Then
Dim p13fso
Set p13fso = Server.CreateObject("Scripting.FileSystemObject")
If p13fso.FileExists(Server.Mappath(filename)) Then p13_FileExist = True Else P13_FileExist = False
Else
P13_FileExist = False
End If
End Function
Random Text v1.2
Random Text Generator (usefull for generating random passwords)
Code:
'***P13 Random Text v1.2 by Ferruh Mavituna
'//NFO//
' Generate random texts by select lenght and pattern
'//ARGUMENTS//
' lenght : Lenght of string will be generate
' rp_chars : Adds Special pattern for generate
' lcases : Include Lowercase Characters (1=active/0=deactive)
' ucases : Include Uppercase Characters (1=active/0=deactive)
' exchars : Include Extra Characters (1=active/0=deactive)
' numbers : Include Numbers(1=active/0=deactive)
'//SAMPLES//
' Response.Write P13_RandomPass(7,"p13studio",0,0,0,0)
' This will generate some random texts just from p,1,3,s,t,d,i,o and this texts lenght is 7
' Response.Write P13_RandomPass(10,"*+-",1,1,0,0)
' This will generate some random texts just from lowercases, uppercases, and *,+,- also this texts lenght is 10
Function P13_RandomPass(lenght,rp_chars,lcases,ucases,exchars,numbers)
Dim rp_lchars, rp_uchars, rp_,rp_ranval, rp_RndInt, rp_exchars, rp_numbers
If lenght = 0 Then lenght = 7
rp_lchars = "abcdefghijklmnopqrstuvwxyz"
rp_uchars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
rp_exchars = "`~!@#$%^&*()-_=+[{]}\\|;:"""'\,<.>/? "
rp_numbers = "0123456789"
If lcases = 1 Then rp_chars = rp_chars & rp_lchars
If ucases = 1 Then rp_chars = rp_chars & rp_uchars
If exchars = 1 Then rp_chars = rp_chars & rp_exchars
If numbers = 1 Then rp_chars = rp_chars & rp_numbers
If rp_chars = "" Then rp_chars = "p13studio"
For i = 1 to lenght
Randomize Timer
rp_RndInt = Int(Rnd*Len(rp_chars)+1)
rp_ranval = rp_ranval & Mid(rp_chars,rp_RndInt,1)
Next
P13_RandomPass = rp_ranval
End Function
Special Variable Writer
I'm using this function for database based multilingual projects.
Code:
'***P13 Special Variable Writer by Ferruh Mavituna
'//NFO//
' Replace a special $author with an ASP Variable
'//ARGUMENTS//
' valx = All text
' variablex = ASP Variable (For two or more variables split them by (-) negotation sign)
' repvariable = $Variable (For two or more $variables split them by (-) negotation sign)
'//PLEASE NOTE//
' If you use multiple variable change use variables same order
' DO : val1-val2,$val1-$val2
' DON'T : val1-val2,$val2-$val1
'//SAMPLES//
' P13_Variable(l.Fields.Item("ranktitle").Value,deger,"$rank")'
' P13_Variable(l.Fields.Item("ranktitle").Value,deger-deger2,"$rank-$rank2")'
Function P13_Variable(valx,variablex, repvariable)
Dim vararr, repvararr, vari
If valx <> "" Then
P13_Variable = valx
vararr = Split(variablex,"-",-1,1)
repvararr = Split(repvariable,"-",-1,1)
For vari = 0 to Ubound(vararr)
P13_Variable = Replace(P13_Variable,Trim(repvararr(vari)),Trim(vararr(vari)),1,-1,1)
Next
End If
End Function
Lettergraph v1.1
This is a standart text to image function.
Code:
'***Lettergraph v1.1 by Ferruh Mavituna
'//NFO//
' Write Letters as images
'//ARGUMENTS//
' valx : Text (alphanumeric)
'//SAMPLE//
' Response.Write P13_Lettergraph("soul")
' >>> Need alphabet folder <<<
'******************************
'Function P13_Lettergraph(valx,folder)
' If folder = "" Then folder ="alphabet"
'******************************
Function P13_Lettergraph(valx)
Dim ix, ix2, valxarr, curletter, lmod
If valx <> "" Then
valxarr = Split(Trim(valx)," ")
For ix2 = 0 to Ubound(valxarr)
For ix = 1 to Len(valxarr(ix2))
curletter = Left(valxarr(ix2),1)
'// Turkish Character Map
If Ucase(curletter) = "Ş" Then curletter = "s2"
If Ucase(curletter) = "Ğ" Then curletter = "g2"
If Ucase(curletter) = "i" Then curletter = "i2"
If Ucase(curletter) = "Ü" Then curletter = "u2"
If Ucase(curletter) = "Ö" Then curletter = "o2"
If ix2 mod 2 Then lmod = "2" Else lmod = ""
P13_Lettergraph = P13_Lettergraph & "<img src=""13mg/lt" & lmod &"/" & curletter &".gif"" alt=""" & curletter & """ />"
valxarr(ix2) = Right(valxarr(ix2),Len(valxarr(ix2))-1)
Next
If ix2 < Ubound(valxarr) Then P13_Lettergraph = P13_Lettergraph & "<img src=""13mg/lt/dot.gif"" alt=""dot"" />"
Next
End If
End Function
Timer
This is one of my favorite small function, It's very usefull for show proccess times.
Put a timer top of your page like
Code:
Dim Xtimer
Xtimer = Timer
Call this func at the end of your page
Code:
Response.Write P13_Timer(timer-timex)
Function;
Code:
'***P13 Timer v1.3 by Ferruh Mavituna
'//NFO//
' Make clock tiemr format
'//ARGUMENTS//
' timex : Time as Second
'//RETURN//
'Some String Like 00:15
'//SAMPLE//
' Response.Write P13_Timer(timer)
Function P13_Timer(timex)
Dim mn, sc, mntxt, sctxt
If isnumeric(timex) Then
'// Format Minute
mn = Round(timex/60,0)
if mn < 0 Then mn = 0
if mn < 10 Then mntxt = "0"
mntxt = mntxt & mn
'// Format Second
sc = Round(timex Mod 60,0)
if sc < 0 Then sc = 0
if sc < 10 Then sctxt = "0"
sctxt = sctxt & sc
'// Final
P13_Timer = mntxt & ":" & sctxt
Else
P13_Timer = "Error value is not numeric !"
End If
End function
Bookmarks