1. Several common functions
Round (PI, 2) Rounding
Formatnumber (K, 4) 'format K to the number of four decimal places.
Eg. If K = 20000, the value is 20,000.00. If formatnumber (K, 0) is set to 20,000
Replace (expression, find, replacewith) 'returns a string with the specified substring replaced by another substring.
Left (string, length) 'returns the string of the specified number counted from the left of the string.
Split (expression [, delimiter [, Count [, start]) 'returns a zero-dimensional array containing a specified number of substrings.
Eg. This split (string, [delimiter]) 'is commonly used to divide strings using delimiter (character used to identify the substring boundary ).
Instr (string1, string2) 'returns the position of a string that appears for the first time in another string.
Eg1. if instr (addation, "password configuration table") <> 0 then' indicates the existence
Eg2. if instr (STR, "AP")> 0 cannot distinguish STR = (AP, AP & AC), as long as it changes to ('ap ', 'ap & AC '), use instr (STR, "'ap '")
2. Pick value in the pop-up window
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 controls the image display size (proportional scaling)
<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 & gt; = 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 & gt; 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 "> </a>
</Body>
</Html>
4. insert/update/delete operations on database tables in ASP. transactions can be used and multi-transaction processing is supported.
In the ASP database object link object, the following attributes are provided:
Begintrans transaction start
Committrans transaction commit
Rollbacktrans transaction rollback
<%
On Error resume next 'Continue processing after the error occurs
'Use transactions in ASP
Set conn = server. Createobject ("ADODB. Connection ")
Conn. Open "course_dsn", "course_user", "course_password"
Conn. begintrans 'Start the transaction
SQL = "delete from user_info"
Set rs = server. Createobject ("ADODB. recordset ")
Rs. Open SQL, Conn, 3, 3
If conn. errors. Count> 0 then 'has an error
Conn. rollbacktrans roll back
Set rs = nothing
Conn. Close
Set conn = nothing
Response. Write "transaction failed, rolled back to the status before modification! "
Response. End
Else
Conn. committrans 'commit a transaction
Set rs = nothing
Conn. Close
Set conn = nothing
Response. Write "transaction successful! "
Response. End
End if
%>
In ASP, the transaction ends are not provided. begintrans only act on their own domains, similar to variable declarations. If begintrans are in the function body, the transaction only acts on the function body, if the begintrans function is in the external body and at the page level, the transaction scope starts from begintrans and ends at the end of the page.
5. easysales database operations
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-format email sending
Html = "<HTML>"
Html = HTML & "Html = HTML & "<title> sending cdonts email using HTML </title>"
Html = HTML & "<link href =" ../CN/new.css "rel =" stylesheet "type =" text/CSS ">"
Html = HTML & "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 & "Dim strrecemail, strposemail, strsubject, strbody
Strrecemail = request ("email ")
Strposemail = "yufh@alleasy.com.cn"
Strsubject = "Document Download notification"
Strbody = html
7. The input is an underscore.
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
Write a session:
Session ["username"]) = "AA ";
Session ("username") = "AA"
Read a sessinn:
String username = session ["username"];
Dim username = SESSION ("username ")
Cookie usage is roughly the same as this
9. constants in several VB
The following constants are defined by the Type Library in Visual Basic for Applications and can be used to replace the actual values anywhere in the Code:
Constant equals description
Vbcrlf CHR (13) + CHR (10) carriage returns combined with line breaks
Vbcr CHR (13) carriage return
Vblf CHR (10) line feed
The new line character specified by vbnewline CHR (13) + CHR (10) platform; applicable to the current platform
Character whose vbnullchar CHR (0) value is 0
A string with a vbnullstring value of 0 is used to call an external process. It is different from a string with a zero length ("").
Vbobjecterror-2147221504 the User-Defined error number must be greater than this value. For example:
Err. Raise number = vbobjecterror + 1000
Vbtab CHR (9) tab.
Vbback CHR (8) return character
10. The button is unavailable.
<% If rsview. EOF and rsview. bof then %> 'There is a big problem here.
<Input name = "Submit" type = 'submit 'value =' unbind the specified user 'Disabled>
<% Else %>
<Input name = "Submit" type = 'submit 'value = 'unlock selected users'>
</TD>
<% End if %>