重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

vb.net类的编写 vbnet single

vb.net 写一个类?

Public Class Name1

创新互联专注于企业成都全网营销、网站重做改版、蚌埠网站定制设计、自适应品牌网站建设、H5技术成都商城网站开发、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为蚌埠等各大城市提供网站开发制作服务。

Public Function fun1()

...

End Function

....

End Class

VB.NET中标准的实体类怎么写的,请教VB高手指导

'代码来源:代码街codejie.net

'由于在vb.net里变量名不区分大小写(StuName和stuname是一样的),所以个别变量名需要修改

'在vb.net中,模块级变量的命名原则是以m_开头

Public Class Student

Private m_stuNo As String '学生号字段

Private m_stuName As String '学生姓名字段

Private m_stuAge As Integer '学生年龄字段

Private m_stuAddress As String '学生住址字段

'无参构造方法

Public Sub New()

End Sub

'有参构造方法

Public Sub New(ByVal stuNo As String, ByVal stuName As String, ByVal stuAge As Integer, ByVal stuAddress As String)

m_stuNo = stuNo

m_stuName = stuName

m_stuAge = stuAge

m_stuAddress = stuAddress

End Sub

'学生号属性

Public Property StuNo() As String

Get

Return m_stuNo

End Get

Set(ByVal value As String)

m_stuNo = value

End Set

End Property

'学生姓名属性

Public Property StuName() As String

Get

Return m_stuName

End Get

Set(ByVal value As String)

m_stuName = value

End Set

End Property

'学生年龄属性

Public Property StuAge() As Integer

Get

Return m_stuAge

End Get

Set(ByVal value As Integer)

m_stuAge = value

End Set

End Property

'学生住址属性

Public Property StuAddress() As String

Get

Return m_stuAddress

End Get

Set(ByVal value As String)

m_stuAddress = value

End Set

End Property

End Class

vb.net中创建类

不熟悉VB,如有不妥的地方请包涵!

Public Class Stack

Dim aryData() As Integer

Sub New(ByVal Num As Integer)

Dim aryData(Num) As Integer

End Sub

Function Pop() As Integer

If (aryData.Length = 0) Then

Return 0

Else

Dim a As Integer

a = aryData(aryData.Length)

aryData(aryData.Length) = Convert.ToInt32(DBNull.Value)

Return a

End If

End Function

Sub Push(ByVal n As Integer)

For Each i As Integer In aryData

If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then

aryData(i) = n

End

Else

Continue For

End If

Next

End Sub

Sub PrintStack()

For Each i As Integer In aryData

If (aryData(i) = Convert.ToInt32(DBNull.Value)) Then

End

Else

Print(aryData(i))

End If

Next

End Sub

End Class

vb.net 如何在一个项目中创建类,并且使用他?

在任意form类或模块中都可以创建类,跟建立函数和过程一样。

示例:

public class form1

‘创建一个属于form的子类,名称为【类名】。

public class 类名

’定义类成员text

public text as string

end class

‘定义一个【类名】类的公共变量。

dim 类名1 as 类名

’定义一个过程,使用【类名】类的text成员

public sub 过程

‘实例化【类名1】

类名1=new 类名

类名1.text=“赋值”

’定义一个【新类】类的私用变量,并实例化。

dim 新类1 as new 新类

新类1.name=“一个字符串”

新类1.age=12

end sub

end class

‘’‘创建一个与form同级的类,名称为【新类】

public class 新类

public sub new()

end sub

public name as string

public age as integer

end class

在模块中使用:

public class module1

dim a as new form1.类名

end module


网站名称:vb.net类的编写 vbnet single
URL分享:http://cqcxhl.com/article/doehspi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP