关于用VBScript定义类的问题:

gymxyl 2004-10-15 11:18:06
例如用VBScript定义了一个类,如下:
class LNode
public col
public value
End class
请问如何把一个变量(如a)设成是这种类?如何引用这个类(变量)的成员变量(col、value)?
有没有关于vbscript的比较全面的书可以推荐看?
...全文
220 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2004-10-16
  • 打赏
  • 举报
回复
<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>
zerocci 2004-10-15
  • 打赏
  • 举报
回复
class LNode
public col
public value
End class

class A
Inherits LNode
End class
gymxyl 2004-10-15
  • 打赏
  • 举报
回复
如果再定义一个类,其中类的成员变量想把它定义成结构LNode型的,可以实现吗?
就是说类套类,可以吗?
rabbit666 2004-10-15
  • 打赏
  • 举报
回复
set a = new lnode
a.value=
xiangyyy 2004-10-15
  • 打赏
  • 举报
回复
gymxyl 2004-10-15
  • 打赏
  • 举报
回复
那怎样才能嵌套定义?
celliona 2004-10-15
  • 打赏
  • 举报
回复
这样不行,vbscript类不支持继承和多态

28,409

社区成员

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

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