1. 幾個常用函數(shù)
Round(pi, 2) 四舍五入
FormatNumber(k,4) ' 把 k 格式化為帶四位小數(shù)點的數(shù)。
eg. 如果k =20000則顯示為20,000.00;如果把formatnumber(k,0)則為20,000
Replace(expression,find,replacewith) '返回一字符串,其中指定的子串已被另一個子串替換
Left(String,Length) '返回指定數(shù)目的從字符串的左邊算起的字符串。
Split(expression[, delimiter[, count[, start]]]) '返回基于 0 的一維數(shù)組,其中包含指定數(shù)目的子字符串。
eg. 常用這個 Split(String,[delimiter]) ' 用delimiter(用于標識子字符串界限的字符)來劃分字符串
Instr(String1,String2) '返回某字符串在另一字符串中第一次出現(xiàn)的位置
eg1. if instr(addation,"密碼配置表")<>0 then '說明存在
eg2. if instr(str,”AP”) >0 不好區(qū)分str = (AP,AP&AC),此時只要變?yōu)椋?#8217;AP’,’AP&AC’),再用instr(str,”’AP’”)
2. 彈出窗口Pick值
function pickupSP(spdisid,pjnum,pdcode)
{
window.opener.<%=theForm%>.RefNum<%=Spid%>.value=spdisid;
window.opener.<%=theForm%>.LineS<%=Spid%>.value=pjnum;
window.opener.<%=theForm%>.kokey<%=Spid%>.value=pdcode;
window.close();
}
3. ASP控制圖片顯示的大小(等比例縮放)
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 164/112){
if(image.width>164){
ImgD.width=164;
ImgD.height=(image.height*164)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
else{
if(image.height>112){
ImgD.height=112;
ImgD.width=(image.width*112)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"x"+image.height;
}
}
}
//-->
</script>
</HEAD>
<BODY>
<a href="./img.jpg" target="_blank"><img src="./img.jpg" border="0" width="164" height="112" onload="javascript:DrawImage(this);"></a>
</BODY>
</HTML>
4. ASP中對數(shù)據(jù)庫表的操作(Insert/Update/Delete),可使用事務(wù)處理,并支持多事務(wù)處理.
在ASP的數(shù)據(jù)庫對象鏈接對象中,提供了一下屬性:
BeginTrans 事務(wù)開始
CommitTrans 事務(wù)提交
RollbackTrans 事務(wù)回滾
<%
On Error Resume Next ’錯誤發(fā)生后繼續(xù)處理
'Asp中使用事務(wù)
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "course_dsn","course_user","course_password"
conn.begintrans '開始事務(wù)
sql="delete from user_info"
set rs=server.createobject("adodb.recordset")
rs.open sql,conn,3,3
if conn.errors.count>0 then '有錯誤發(fā)生
conn.rollbacktrans '回滾
set rs=nothing
conn.close
set conn=nothing
response.write "交易失敗,回滾至修改前的狀態(tài)!"
response.end
else
conn.committrans '提交事務(wù)
set rs=nothing
conn.close
set conn=nothing
response.write "交易成功!"
response.end
end if
%>
在ASP中,不提供事務(wù)的結(jié)束,BeginTrans只作用于自己的域,類似于變量聲明一樣,如果在函數(shù)體內(nèi)BeginTrans,則事物只作用于本函數(shù)體,如果BeginTrans在函數(shù)體外,處于頁面級,則事務(wù)的作用域從BeginTrans開始,到頁面的結(jié)束均處于事務(wù)的管理狀態(tài)下.
5. EasySales數(shù)據(jù)庫操作
dim objCon,objRst,objsql
dim companyid
Set objCon = Server.CreateObject("ADODB.Connection")
objCon.Open SYSDNS,SYSNAME,SYSPASSWORD
Set objRst = Server.CreateObject("ADODB.RecordSet")
objsql="select * from PasswordConfig where companyid='"&session("CompanyID")&"'"
objRst.Open objsql,objCon,1,3
6. html格式郵件發(fā)送
HTML = "<html>"
HTML = HTML & "<head>"
HTML = HTML & "<title>Sending CDONTS Email Using HTML</title>"
HTML = HTML & "<link href="../cn/new.css" rel="stylesheet" type="text/css">"
HTML = HTML & "</head>"
HTML = HTML & "<body bgcolor=""FFFFFF"">"
HTML = HTML & "<p><font size=7>"
HTML = HTML & "This is a test mail in html<br>"
HTML = HTML & "Mail content here ...</font></p>"
HTML = HTML & "</body>"
HTML = HTML & "</html>"
dim StrRecEmail,StrPosEmail,StrSubject,StrBody
StrRecEmail=request("email")
StrPosEmail="yufh@alleasy.com.cn"
StrSubject="資料下載通知函"
StrBody=HTML
7. input是下劃線
style="BORDER-RIGHT: #f7f7f7 0px solid; BORDER-TOP: #f7f7f7 0px solid; FONT-SIZE: 9pt; BORDER-LEFT: #f7f7f7 0px solid; WIDTH: 110px; BORDER-BOTTOM: #c0c0c0 1px solid; HEIGHT: 16px; BACKGROUND-COLOR: #f7f7f7"
8. Session & Cookie
寫入一個SESSION:
Session["username"])="aa";
Session("username")="aa"
讀取一個SESSINN:
string username= Session["username"];
dim username=Session("username")
Cookie與此用法大致相同
9. 幾個VB中的常數(shù)
下列常數(shù)由 Visual Basic for Applications 中的類型庫定義,可用來在代碼中的任何地方代替實際值:
常數(shù) 等于 描述
vbCrLf Chr(13) + Chr(10) 回車符與換行符結(jié)合
vbCr Chr(13) 回車符
vbLf Chr(10) 換行符
vbNewLine Chr(13) + Chr(10) 平臺指定的新行字符;適用于當(dāng)前平臺
vbNullChar Chr(0) 值為 0 的字符
vbNullString 值為 0 的字符串 用來調(diào)用外部過程;與長度為零的字符串 ("") 不同
vbObjectError -2147221504 用戶定義的錯誤號應(yīng)當(dāng)大于該值,例如:
Err.Raise Number = vbObjectError + 1000
vbTab Chr(9) Tab 字。
vbBack Chr(8) 退格字符
10. 按鈕為不可用
<%if rsView.eof and rsView.bof then %> ‘ 這里有個大問題,下文再說
<input name="submit" type='submit' value='對選定用戶解鎖' disabled>
<%else%>
<input name="submit" type='submit' value='對選定用戶解鎖' >
</td>
<%end if%>