ASP中的类对象怎么编?

cuayi 2004-11-21 12:35:39
请问一下,
ASP中的类对象怎么编?
编写格式有哪些讲究?
能给点简单的例子加以说明吗?
先谢谢大家!
...全文
193 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
cuayi 2004-11-22
  • 打赏
  • 举报
回复
比方我要将下面分页代码编成一个类。以方便下次调用,怎么编?
一起把调用语句写一下。谢谢!

<%
sql = "数据表链接语句"
rs.open sql,conn,1,1
if rs.eof then
else
rs.pagesize = 4
page = cint(Request.QueryString("page"))
if page = "" then page = 1
if page < 1 then page = 1
if page >= rs.pagecount then page = rs.pagecount
rs.absolutepage=page
for i = 1 to rs.pagesize
%>

(列表数据)

<%
rs.movenext
if rs.eof then exit for
next
end if
%>

<% if page>1 then %>
<a href="<%= request.servervariables("document_name") %>?page=1">[首页] </a><a href="<%= request.servervariables("document_name") %>?page=<%= page-1 %>">[前页]</a>
<% else %>
<font color="#999999">[首页] [前页]</font>
<% end if %>
<% if page <> rs.pagecount then %>
<a href="<%= request.servervariables("document_name") %>?page=<%= page+1 %>">[后页] </a><a href="<%= request.servervariables("document_name") %>?page=<%= rs.pagecount %>">[尾页]</a>
<% else %>
<font color="#999999">[后页] [尾页]</font>
<% end if %>
<%
rs.close
set rs = nothing
%>
abaowu 2004-11-22
  • 打赏
  • 举报
回复
<%
/*********************************************************/
/* Admin Class JScript                   */
/*                 */
/*********************************************************/
//Member Method Define

//检测用户名是否存在(通用)
function _isExitsUser(userName)
{
try
{
//var conn = this.conn;
var flag ;
var sql = " select memBasInfId from M_MemBasInf where memUserName = '" + userName + "' ";
var rs = Server.CreateObject("ADODB.Recordset");
rs.open(sql,this.conn,1,1);
flag = ( rs.Eof == true ? false : true );
return flag;
}
finally
{
closeObj(rs);
}

}

//获取用户ID
function _getUserIdByUserName(userName)
{
try
{
userName = String(userName).trim();
//var conn = this.conn;
var userId = 0;
var sql = " select memBasInfId from M_MemBasInf where memUserName = '" + userName + "' ";
//var sql = " select memBasInfId from M_MemBasInf where memUserName = 'abao' ";
var rs = Server.CreateObject("ADODB.Recordset");
rs.open(sql,this.conn,1,1);
if(!rs.eof)
{
userId = rs("memBasInfId");
}
return userId;
}
finally
{
//closeObj(rs);
}
}

//会员登录
function _login(userName,userPas)
{
try
{
userName = sqlStr(String(userName).trim());
userPas = sqlStr(String(userPas).trim());
var flag;
var sql = " select AdminId from T_S_Admin ";
sql += " where AdminName = '" + userName + "' and AdminPaswd = '"+userPas+"' ";
var rs = Server.CreateObject("ADODB.Recordset");
rs.open(sql,this.conn,1,1);
flag = ( rs.Eof == true ? false : true );
if(flag)
{
Session("adminName") = userName;
Session("adminPaswd") = userPas;
}
return flag;
}
finally
{
closeObj(rs);
}
}

//会员注销
function _loginOut()
{

}




//更新密码
function _altPassword(oldPas,newPas)
{
try
{
var AdminName = String(Session("AdminName"));
var flag;
flag = false;
var rs = Server.CreateObject("ADODB.Recordset");
var sql = " select AdminId from T_S_Admin ";
sql += " where AdminPaswd = '"+oldPas+"' and AdminName = '"+AdminName+"' ";
rs.open(sql,this.conn,1,1)
if(!rs.eof)
{
sql = "update T_S_Admin set AdminPaswd = '"+newPas+"' where AdminName = '"+AdminName+"' ";
this.conn.Execute(sql);
Session("AdminPaswd") = newPas;//更新密码
flag = true;
}
return flag;
}
finally
{
closeObj(rs);
}
}
//构造函数
function clsAdmin(conn)
{
//property
this.conn = conn;

//method
this.login = _login;
this.altPaswd = _altPassword;


}



%>
cuayi 2004-11-22
  • 打赏
  • 举报
回复
superdullwolf(超级大笨狼,每天要自强)
你的代码有点看不懂。
跟VB中的代码好像啊!

想问一下:
在ASP中,GET和LET 的区别是什么?
cuayi 2004-11-22
  • 打赏
  • 举报
回复
谢谢大家
帮助很大,
大家再多点例子给我看看,希望能加点中文注释.
谢谢.
谢谢syre(神仙),结贴算你一个,能再给个稍微复杂点点的吗?
本贴我加分!
cuayi 2004-11-22
  • 打赏
  • 举报
回复
谢谢各位,有点明白了。
newskyline 2004-11-22
  • 打赏
  • 举报
回复
<%
Class YouClassName
Public MyProperty1 '最简单的方式给类添加一个属性
Dim m_Property2 '定义一个局部变量,给属性MyProperty2用的
Private m_Var3 '定义一个局部变量
Private Sub Class_Initialize()
'构造函数
'在这里初始化你的Class
End Sub
Private Sub Class_Terminate()
'析构函数
'在这里释放资源
End Sub
Public Sub MyMethod1WithoutReturnValue ()
'这是一个无需返回值的方法
End Sub
Public Function MyMethod2WithReturnValue()
'这是一个带返回值的方法
MyMethod2WithReturnValue="OK"
End Function

'以下三个定义了一个属性MyProperty2的三个操作:GET,LET,SET,这三个可以根据需要选用
Public Property Get MyProperty2 ()
MyProperty3=m_Property2
End Property
Public Property Let MyProperty2(newVal)
m_Property2=newVal
End Property
Public Property Set MyProperty2(newVal)
Set MyProperty2=new Val
End Property

End Class
%>
nchen123 2004-11-22
  • 打赏
  • 举报
回复
在可能的情况下, 建议你代码不要用这种客户端服务器端混杂的写法,用 Response.Write 输出比较好; 这样程序可读性好,易维护。效率也高些。 因为 IIS 在解释执行页面的时候,按照混杂的写法就需要不停的在两种解释引擎之间来回切换,效率很低。
-神仙- 2004-11-21
  • 打赏
  • 举报
回复
vbs:
class class1

private field1
public field2

public function func1()
response.write "this is func1()"
end function

public function setF(v)
field1=v
end function

pulic function getF()
getF=v
end function

end class

set c=new class1
c.func1()
c.setV(5)
response.write c.getV()
超级大笨狼 2004-11-21
  • 打赏
  • 举报
回复

<input value="看看superDullWolf的CNWord类引用实例,vbs,改进了一下,可以提供chinese出现的位置了" id="input1" style="width:100%"/>
<br/>
<button onclick="vbs:classAndRegExp">验证</button>
<script language = "vbscript">
sub classAndRegExp()
set wolf = new CNWord
wolf.str = input1.value

msgbox "含有中文数" & wolf.CNcount
msgbox "含有中文块数" & wolf.CNBlockCount
msgbox "第2个中文块是--->" & wolf.CN(2)
msgbox "第1个中文块出现的位置是--->" & wolf.CNIndex(1)
set wolf = nothing
end sub
</script>


<script language="vbscript">
class CNWord

public str

private sub Class_Initialize()
set regEx =new RegExp
regEx.IgnoreCase = True '设置是否区分大小写。
regEx.Global = True '设置全局可用性。
end sub

private regEx


Property get CN(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
dim Match
For each Match in regEx.Execute(str)
Arr(i) = Match
i = i + 1
next
if x<=maxBound then CN = Arr(x)
End Property

Property get CNIndex(x)
dim Arr()
dim maxBound : maxBound = CNBlockCount
redim Arr(maxBound)
dim i:i=1
dim Match
For each Match in regEx.Execute(str)
Arr(i) = Match.FirstIndex + 1
i = i + 1
next
if x<=maxBound then CNIndex = Arr(x)
End Property

Property get CNcount
'返回含有中文的字数
regEx.Pattern = "[\u4e00-\u9fa5]"
CNcount = findCHNnum()
End Property

Property get CNBlockCount
'返回含有中文的块数
regEx.Pattern = "[\u4e00-\u9fa5]+"
CNBlockCount = findCHNnum()
End Property


private function findCHNnum()
findCHNnum = regEx.Execute(str).count
end function




private sub Class_Terminate()
set regEx = nothing
end sub

end class
</script>
yqh1314 2004-11-21
  • 打赏
  • 举报
回复
学习 我还没有学到类
timdy 2004-11-21
  • 打赏
  • 举报
回复
希望你看得懂下面的东西: vbs:
class class1

private field1
public field2

public function func1()
response.write "this is func1()"
end function

public function setF(v)
field1=v
end function

pulic function getF()
getF=v
end function

end class

set c=new class1
c.func1()
c.setV(5)
response.write c.getV()

nchen123 2004-11-21
  • 打赏
  • 举报
回复
http://community.csdn.net/Expert/topic/3354/3354509.xml?temp=.098324
sdts 2004-11-21
  • 打赏
  • 举报
回复
学习了 up
-神仙- 2004-11-21
  • 打赏
  • 举报
回复
我记得好像是property get xxxx
ocean413 2004-11-21
  • 打赏
  • 举报
回复
public get property xx(prar)
field1=prar
end property

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧