189 8069 5689

VB.net函数怎么写 VBNET编程宝典

VB.net 如何编写一个可以返回数组的函数(过程)?

public function createstringarr() as string()

创新互联公司致力于互联网网站建设与网站营销,提供成都网站建设、成都网站设计、网站开发、seo优化、网站排名、互联网营销、成都微信小程序、公众号商城、等建站开发,创新互联公司网站建设策划专家,为不同类型的客户提供良好的互联网应用定制解决方案,帮助客户在新的全球化互联网环境中保持优势。

return new string(){"d1","d2","d3","d4"}

end function

VB.NET自定义函数

很简单,在end select前再多加一种情况case else return "XXXx",因为你只提供了0-9这10种情况

Public Function Zuhe(ByVal qa As String) As String

Select Case qa

Case "0"

Return "1"

Case "1"

Return "3"

Case "2"

Return "4"

Case "3"

Return "6"

Case "4"

Return "2"

Case "5"

Return "8"

Case "6"

Return "9"

Case "7"

Return "7"

Case "8"

Return "5"

Case "9"

Return "0"

Case else

Return "XXXX"

End Select

End Function

vb.net如何重写函数?比如重写ToString。 Dim a As Integer = 1 MessageBox.Show(a.ToString) '重写……

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim a As New month(1)

MessageBox.Show(a.ToString)

End Sub

End Class

Public Class month

Dim m As Integer

Public Sub New(i As Integer)

m = i

End Sub

Public Overrides Function ToString() As String

If m = 1 And m = 12 Then

Return Choose(m, "一", "二", "三", "四", "五", "六", "七", "八", "九", "十", "十一", "十二") + "月"

Else

Return m.ToString

End If

End Function

End Class

vb.net 编写一个函数

注意:参数为动态数组;

Private Function MyF(ByRef d() As Integer)

ReDim d(4, 13) As Integer

Dim i As Integer

Dim j As Integer

Dim n As Integer

Dim MyNum(4) As Integer

For i = 1 To 4

MyNum(i) = 0

Next i

Randomize

For i = 1 To 4

For j = 1 To 13

n = Int(Rnd * 4 + 1)

Do While MyNum(n) = 13

n = Int(Rnd * 4 + 1)

Loop

d(i, j) = n

MyNum(n) = MyNum(n) + 1

Next j

Next i

End Function

使用vb.net编写一个函数,函数只有一个参数

首先在窗体上添加Button1,ListBox1,下面是完整代码

Public Class Form1

Public Sub BubbleSort(ByVal arr() As Integer) '冒泡法排序

Dim temp As Double

Dim i, j As Integer

For i = 0 To arr.GetUpperBound(0) - 1

For j = i + 1 To arr.GetUpperBound(0) - 1

If arr(i)  arr(j) Then

temp = arr(j)

arr(j) = arr(i)

arr(i) = temp

End If

Next

Next

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click '调用

Dim arr() As Integer = {55, 22, 33, 11, 77, 88}

BubbleSort(arr) '调用排序过程

Me.ListBox1.Items.Clear()

For i = 0 To arr.GetUpperBound(0) - 1 '显示排序后结果

Me.ListBox1.Items.Add(arr(i).ToString)

Next

End Sub

End Class


网站名称:VB.net函数怎么写 VBNET编程宝典
网页网址:http://cdxtjz.cn/article/hgegej.html

其他资讯