兩個參數(shù):一個是數(shù)組名,一個是傳遞的長度
成都創(chuàng)新互聯(lián)公司-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比蒙自網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式蒙自網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋蒙自地區(qū)。費(fèi)用合理售后完善,十多年實(shí)體公司更值得信賴。
Function thename(ByVal imgFrom As Image) As String
thename = imgFrom.Name
End Function
Private Sub Image1_Click()
MsgBox thename(Image1)
End Sub
1.對象變量與對象本身是不同的,對象變量代表了對象真實(shí)數(shù)據(jù)在內(nèi)存中的地址.
打個比方,“對象變量”就象你家的地址,“對象本身”就象你家。
你不能說你家的地址(xx路xx號xx房)就是你家,但是可以通過這個地址而找到你家。
2.傳值的參數(shù)本身是被復(fù)制一份的,但這并不意味著它所代表的對象也被復(fù)制一份.
有如下一個函數(shù):
Public
Function
Do_delete(ByVal
ps_usr_id
As
String)
As
Boolean
你在調(diào)用時(shí)可能這樣調(diào)用:
dim
strID
as
string
strID
=
"kknd001"
if
Do_delete(strID)
then.....
當(dāng)程序執(zhí)行到Do_delete函數(shù)體里面時(shí)ps_usr_id變量其實(shí)是按照StrID的值而復(fù)制的一個變量。
新窗體中寫
構(gòu)造函數(shù)
,然后調(diào)用。
比如你要調(diào)用的新窗體是From1.cs這個窗體,
public
Form1(要傳入的參數(shù))
{
//把傳入的參數(shù)傳入窗體中
//執(zhí)行窗體標(biāo)準(zhǔn)內(nèi)容
}
然后在需要調(diào)用的地方調(diào)用
Form1
f
=
new
Form1(傳出的參數(shù));
'--------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();
如此就能實(shí)現(xiàn)調(diào)用了。
線程結(jié)束后利用委托生成事件返回,線程應(yīng)用包括傳入和傳出參數(shù)。
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