类模块是用来声明VB类的,一般用来ActiveX开法中,例如用来操作数据库的ADO,或者也可以尝试引用MS Word.
http://www.xc-soft.com/docs/3tieranddatabase.htm
模块的用途:整个工程中都生效的变量,过程,函数都应该声明在标准模块中。 类模块的用途:用于声明一个用户自定义的类。例如你可以声明一个自定义类book,然后在窗体代码中调用他。 例:以下代码写在类模块中: public class book private m_text as string private m_title as string public property text() as string get return m_text end get set (byval value as string) m_text=value end set end property public property title() as string get return m_title end get set (byval value as string) m_title=value end set end property pulic sub new() end sub end class 以下代码写在窗体中: private sub form_load() dim lhp as book lhp.text="i love you" lhp.tille="i love vb" end sub
声明dim lhp as book 和dim lhp as new book有什么区别? 我在类模块book中写了: Function sum(a As Integer, b As Integer) As Integer sum = a + b End FunctionFunction div(a As Integer, b As Integer) As Integer div = a / b End Function 为什么在使用时要申明“dim lhp as new book”,而不能申明成“dim lhp as book”? 请答复!
sorry,正确的写法是将dim lhp as book 该为dim lhp as new book,目的是创建一个类实例,也就是实例化!
to jary12581(狼): 你所说的类模块的用途太过抽象了!真正在程序中,用类模块带来什么样的方便?什么情况下我考虑用类模块而不用模块,或者两种都用。既然是类模块,那么他的继承和多态怎么使用并且构造函数和析够函数怎么使用?请回答!
类模块的用途:用于声明一个用户自定义的类。例如你可以声明一个自定义类book,然后在窗体代码中调用他。
例:以下代码写在类模块中:
public class book
private m_text as string
private m_title as string
public property text() as string
get
return m_text
end get
set (byval value as string)
m_text=value
end set
end property
public property title() as string
get
return m_title
end get
set (byval value as string)
m_title=value
end set
end property
pulic sub new()
end sub
end class
以下代码写在窗体中:
private sub form_load()
dim lhp as book
lhp.text="i love you"
lhp.tille="i love vb"
end sub
我在类模块book中写了:
Function sum(a As Integer, b As Integer) As Integer
sum = a + b
End FunctionFunction div(a As Integer, b As Integer) As Integer
div = a / b
End Function
为什么在使用时要申明“dim lhp as new book”,而不能申明成“dim lhp as book”?
请答复!
你所说的类模块的用途太过抽象了!真正在程序中,用类模块带来什么样的方便?什么情况下我考虑用类模块而不用模块,或者两种都用。既然是类模块,那么他的继承和多态怎么使用并且构造函数和析够函数怎么使用?请回答!