vb点虐 创建类 vb net

vb点虐 中创建类

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

从事成都西信服务器托管,服务器租用,云主机,网络空间,国际域名空间,CDN,网络代维等服务。

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点虐 如何在一个项目中创建类,并且使用他?

在任意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点虐 自建类生成类e似xx.item(0).value或者xx.Name("zhangshan").Value

'这是数组的一个方法了,可是可以给数组定义扩展方法来实现这种形式。不过要给Item每个成员能动态生成相应方法,想不出其它简单点的办法,只能一个一个的添加扩展方法。

Namespace 测试

Public Class Item

Public Number() As String

Public Name As String

Public Symbol As String

Public Value As Single

Public Unit As String

Public Description As String

Public Remarks As String

End Class

Public Class XX

Public tty() As Item

Public Sub New()

tty(0).Name = "Women"

tty(0).Value = 198000

tty(1).Name = "temen"

tty.Name("temen").Value = 99999

End Sub

End Class

Public Module Module1

System.Runtime.CompilerServices.Extension() _ 

Public Function Name(ByVal she As Item(), ByVal key As String) As Item '定义扩展方法功能 在net.3.5前的版本像似没有。

For Each it In she

If it.Name = key Then

Return it

End If

Next

Return Nothing

End Function

End Module

End Namespace

vb点虐 创建类引用类

你是指……

Dim 变量名 as 类型 = new 类型(构造参数)

这样么

或者是

Dim 变量名 as new 类型(构造参数)

这样?

还是说

Class 类名

End Class

这样?


网页题目:vb点虐 创建类 vb net
转载源于:http://ybzwz.com/article/ddcpohi.html