重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
按值传参byval,和按引用byref
柯桥网站制作公司哪家好,找成都创新互联!从网页设计、网站建设、微信开发、APP开发、响应式网站开发等网站项目制作,到程序开发,运营维护。成都创新互联2013年至今到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选成都创新互联。
vb.net里默认是byval,这和vb6不同 :)
线程结束后利用委托生成事件返回,线程应用包括传入和传出参数。
Public Delegate Sub ThreadCallback(value As ThreadResult)
Public Class Form1
Private WithEvents _th_1 As Thread_1
Protected Overrides Sub OnLoad(e As System.EventArgs)
Dim value As ThreadObject
value.Index = 1
Me._th_1 = New Thread_1(Me)
Me._th_1.Run(value)
MyBase.OnLoad(e)
End Sub
Private Sub Thread_1_End(sender As Object, e As ThreadEventArgs) Handles _th_1.ThreadEnd
Me.TextBox1.Text = e.Result.Text
End Sub
End Class
Public Class Thread_1
Public Event ThreadEnd(sender As Object, e As ThreadEventArgs)
Private _control As Control
Sub New(control As Control)
Me._control = control
End Sub
Public Sub Run(value As Object)
Dim th As New Threading.Thread(AddressOf ThreadProc)
th.Start(value)
End Sub
Private Sub ThreadProc(obj As Object)
Dim value As ThreadObject = CType(obj, ThreadObject)
Dim result As ThreadResult = Nothing
If value.Index = 1 Then result.Text = "测试"
Dim callback As New ThreadCallback(AddressOf ThreadInvoke)
_control.Invoke(callback, result)
End Sub
Private Sub ThreadInvoke(value As ThreadResult)
RaiseEvent ThreadEnd(Me, New ThreadEventArgs(value))
End Sub
End Class
Public Structure ThreadObject
Public Index As Integer
'Public Rect As Rectangle
End Structure
Public Structure ThreadResult
Public Text As String
'Public Rect As Rectangle
End Structure
Public Class ThreadEventArgs
Inherits System.EventArgs
Private _result As ThreadResult
Public ReadOnly Property Result As ThreadResult
Get
Return _result
End Get
End Property
Sub New(value As ThreadResult)
Me._result = value
End Sub
End Class
新窗体中写
构造函数
,然后调用。
比如你要调用的新窗体是From1.cs这个窗体,
public
Form1(要传入的参数)
{
//把传入的参数传入窗体中
//执行窗体标准内容
}
然后在需要调用的地方调用
Form1
f
=
new
Form1(传出的参数);
'--------Form1--------
Dim
f2
As
Form2
Private
Sub
Command1_Click()
Set
f2
=
New
Form2
f2.Show
vbModal
End
Sub
'--------Form1
End--------
'--------Form2--------
Dim
WithEvents
f3
As
Form3
Private
Sub
Command1_Click()
Set
f3
=
New
Form3
f3.Show
End
Sub
Public
Sub
f3_f2W()
Me.Command1.Caption
=
"f2W"
End
Sub
'--------Form2
End--------
'--------Form3--------
Public
Event
f2W()
Private
Sub
Command1_Click()
RaiseEvent
f2W
End
Sub
'--------Form3
End--------
f.Show();
如此就能实现调用了。
public structure struc
public name as string
public shengao as integer
……
end structure
public items as struc()
readonly property people(argname as string) as struc
get
for each i as struc in items
if i.name=argname then reture i
next
end get
end property
struc可以用class,property可以用function,people通过参数返回一个对象,对象可以来源于某个数组的某个元素,也可以是其他来源。
people也可以是类的构造方法,而shengao等是类的成员,但你的写法是错误的,构造方法必须用new实例化
VB.NET可选参数的默认值必须是一个常数表达式。
过程定义中跟在可选参数后的每个参数也都必须是可选的。
下面的语法显示带VB.NET可选参数的过程声明:
Sub sub name(ByVal parameter 1 As data type 1,
Optional ByVal parameter 2 As data type 2 = default value)
调用带VB.NET可选参数的过程
过程在运行时无法检测到给定的参数是否已被省略,或者调用代码是否已显式提供默认值。如果需要弄清楚这一点,可以设置一个不可能的值作为默认值。下面的过程定义了可选参数 office,并测试其默认值 QJZ 以查看它在调用中是否已被省略:
Visual Basic
Sub notify(ByVal company As String, Optional ByVal office As String = "QJZ")
If office = "QJZ" Then
Debug.WriteLine("office not supplied -- using Headquarters")
office = "Headquarters" End If
' Insert code to notify headquarters or specified office.
End Sub
如果可选参数是像 String 这样的引用类型,只要它不是该变量所预期的值,就可以使用 Nothing 作为默认值。
VB.NET可选参数和重载
定义带可选参数的过程的另一种方法是使用重载。如果有一个可选参数,可以定义过程的两个重载版本,一个接受此参数,另一个则不带参数。此方法随可选参数数目的增加而变得更复杂。然而,这样做的优点是可以完全确定调用程序是否提供了每个VB.NET可选参数。
两个参数:一个是数组名,一个是传递的长度
Function thename(ByVal imgFrom As Image) As String
thename = imgFrom.Name
End Function
Private Sub Image1_Click()
MsgBox thename(Image1)
End Sub