1.往组合框添加条目
With Me .ComboBox1.Items
.Add( "Ports" )
.Add( "Igor" )
End With
2.文本框Select Case
Private Sub Fname1() Handles ComboBox1.SelectedValueChanged
Select Case ComboBox1.SelectedItem
Case "Drivers"
Me .ListBox1.Items.Clear()
Me .ListBox1.Items.Add("Drivers" )
Case "Ports"
Dim i As Integer =
Dim m = My .Computer.Ports.SerialPortNames.Count
Me .ListBox1.Items.Clear()
For i = To m -
Me .ListBox1.Items.Add(CStr ( My.Computer.Ports.SerialPortNames(i)))
Next
End Select
End Sub
3.CType对象转换
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Try
Dim SelectedRange As Excel.Range = _
Application.InputBox(Prompt:= _
"Select the cell or cells to add random value." , _
Title:= "random values" , _
[Default]:= CType (Application.Selection, Excel.Range).Address, Type:=)
SelectedRange.Value = "=rand()"
Catch ex As Exception End Try
End Sub
也可以:
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Try
Dim Selection As Excel.Range = Me.Application.Selection
Dim SelectedRange As Excel.Range = _
Application.InputBox(Prompt:= _
"Select the cell or cells to add random value.", _
Title:="random values", _
[Default]:=Selection.Address, Type:=)
SelectedRange.Value = "=rand()"
Catch ex As Exception End Try
End Sub
4. 函数创建及调用
Private Sub ThisWorkbook_Startup() Handles Me.Startup
Try
Dim i As Double
Dim Selection As Excel.Range = Me.Application.Selection
Dim SelectedRange As Excel.Range = _
Application.InputBox(Prompt:= _
"Select the cell or cells to add random value.", _
Title:="random values", _
[Default]:=Selection.Address, Type:=)
i = Rnd()
SelectedRange.Value = myFunction(i)
Catch ex As Exception End Try
End Sub Function myFunction(ByVal j As Double) As Double
myFunction = * j
Exit Function
End Function