1.with...end with
With Button1
.Text = "ok"
.Visible = True
.Top = 200
End With
2.獲得對象類型(或者說屬于哪個類)
If Typeof(myForm) Is Form Then
'Typeof 後面隻能接is,看來隻能用在if語句中
End If
TypeName(myForm) As String '可以用在任何位置
3.CallByName 函數執行對象的方法,或者設定或傳回對象的屬性。智能裝置不支援此函數.
Public Function CallByName( _
ByVal ObjectRef As System.Object, _
ByVal ProcName As String, _
ByVal UseCallType As CallType, _
ByVal Args() As Object _
) As Object
第一個參數ObjectRef表示要操作的對象.第二個參數ProcName表示要操作的方法、屬性或者過程名稱的字元表示.第三個參數UseCallType是一個常數選項,CallType枚舉 類型的枚舉成員,當操作是一個方法時,值是vbMethod;當被操作的是設定屬性時,值是vbLet;得到屬性時,值是vbGet;設定對象屬性的值時,值是vbSet.第四個參數Args是可選的ParamArray,參數數組,包含要傳遞給所調用的屬性和方法的參數。
Imports Microsoft.VisualBasic.CallType
'在下面的示例中,第一行使用 CallByName 設定文本框的 Text 屬性,第二行檢索 Text 屬性的值,第三行調用 Move 方法以移動文本框。
Sub TestCallByName1()
'Set a property.
CallByName(TextBox1, "Text", CallType.Set, "New Text")
'Retrieve the value of a property.
MsgBox(CallByName(TextBox1, "Text", CallType.Get))
'Call a method.
CallByName(TextBox1, "Hide", CallType.Method)
'下一個示例使用 CallByName 函數調用集合對象的 Add 和 Item 方法。
Public Sub TestCallByName2()
Dim col As New Collection()
'Store the string "Item One" in a collection by
'calling the Add method.
CallByName(col, "Add", CallType.Method, "Item One")
'Retrieve the first entry from the collection using the
'Item property and display it using MsgBox().
MsgBox(CallByName(col, "Item", CallType.Get, 1))
End Sub
End Sub