CopyCode The Code is as follows: '*************************************** **********
'Function name: getmaxorder
'For use: obtain the maximum serial number.
'Parameter: fieldname ---- field name in the serial number table
'Tablename ---- name of the table with the serial number
'Fieldname ---- field name in the table
'Return value: maximum value of a field
'Call the function: idadd: For more information, see.
'*************************************** **********
Function getmaxorder (fieldname, tablename, tablefilename)
Dim orderno, orderrs, testrs
Set testrs = server. Createobject ("ADODB. recordset ")
Set orderrs = server. Createobject ("ADODB. recordset ")
Firstno = year (date) & right ("0" & month (date), 2)
Ordersql = "select * From fieldmaxvalue where fieldname = '" & fieldname &"'"
Orderrs. Open ordersql, Conn, 3, 2
If not orderrs. EOF then
Orderrs ("fieldmaxvalue") = orderrs ("fieldmaxvalue ")
Orderno = orderrs ("fieldmaxvalue ")
If left (orderno, 6) = firstno then
Orderno = idadd (orderno)
Else
Orderno = firstno & "00001"
End if
Else
Orderrs. addnew
Orderrs ("fieldname") = fieldname
Orderno = firstno & "00001"
End if
Testrs. Open "select max (" & tablefilename & ") from" & tablename & "where" & tablefilename & "like '" & firstno & "%'", Conn, 1, 2
If (not testrs. EOF) and testrs (0). value> orderno then
Orderno = idadd (testrs (0). value)
End if
Testrs. Close
Set testrs = nothing
Orderrs ("fieldmaxvalue") = orderno
Orderrs. Update
Orderrs. Close
Set orderrs = nothing
Getmaxorder = orderno
End Function
'*************************************** **********
'Function name: idadd
'Usage: Used to add one: for example, idadd ("5") = "6", idadd ("l99") = "m00", idadd ("! ") = "! 1"
'If it is a number, it is 9, and if it is a lowercase letter, it is Z after expiration.
'If it is an uppercase letter to the last digit of Z, add one to the other
'Parameter: Id ---- the number to be added
'Return value: the added number.
'Call the function: Add addone ("5") = "6", add (9) = "0", addone ("A") = "B ",
'Addone ("Z") = "A", addone ("A") = "B", addone ("Z") = ""
'*************************************** **********
Function addone (first)
Dim tempfirst
Addone = first
Intfirst = ASC (first)
If (intfirst> = 48 and intfirst <57) or (intfirst> = 65 and intfirst <90) or (intfirst> = 97 and intfirst <122) then
Addone = CHR (intfirst + 1)
Exit Function
End if
If (intfirst = 57) then
Addone = "0"
Exit Function
End if
If (intfirst = 90) then
Addone = ""
Exit Function
End if
If (intfirst = 122) then
Addone = ""
Exit Function
End if
End Function
Function idadd (ID)
Dim fornt, back, strfind, strbackfind, idlen, tempid
If Id = "" Or isnull (ID) then
Iddadd = 1
Exit Function
End if
Tempid = ID
Idlen = Len (ID)
For I = 1 to idlen
Fornt = left (ID, idlen-I)
Back = right (ID, I-1)
Strfind = mid (ID, idlen + 1-I, 1)
Strbackfind = addone (strfind)
Id = fornt & strbackfind & back
If strfind <strbackfind then
Exit
End if
If strfind> strbackfind then
If I = idlen then
Id = ID & "1"
Else
If mid (ID, idlen-I, 1) = addone (mid (ID, idlen-I, 1) then
Id = fornt & strbackfind & back & "1"
Exit
End if
End if
End if
Next
If Id = tempid then
Id = ID & "1"
End if
Idadd = ID
End Function
'Call example
Serviceno = getmaxorder ("serviceno", "service", "serviceno ")
'The structure of the table that stores the maximum number of flow numbers for all fields is:
Table Name: fieldmaxvalue
Field
Id fieldname fieldmaxvalue