zoukankan      html  css  js  c++  java
  • VSTO 基础随笔

    1.往组合框添加条目

    1      With Me .ComboBox1.Items
    2             .Add( "Ports" )
    3             .Add( "Igor" )
    4         End With

    2.文本框Select Case

     1      Private Sub Fname1() Handles ComboBox1.SelectedValueChanged
     2         Select Case ComboBox1.SelectedItem
     3             Case "Drivers"
     4                 Me .ListBox1.Items.Clear()
     5                 Me .ListBox1.Items.Add("Drivers" )
     6             Case "Ports"
     7                 Dim i As Integer = 0
     8                 Dim m = My .Computer.Ports.SerialPortNames.Count
     9                 Me .ListBox1.Items.Clear()
    10                 For i = 0 To m - 1
    11                     Me .ListBox1.Items.Add(CStr ( My.Computer.Ports.SerialPortNames(i)))
    12                 Next
    13         End Select
    14     End Sub

    3.CType对象转换

     1      Private Sub ThisWorkbook_Startup() Handles Me.Startup
     2         Try
     3             Dim SelectedRange As Excel.Range = _
     4                 Application.InputBox(Prompt:= _
     5                     "Select the cell or cells to add random value." , _
     6                     Title:= "random values" , _
     7                     [Default]:= CType (Application.Selection, Excel.Range).Address, Type:=8)
     8             SelectedRange.Value = "=rand()"
     9         Catch ex As Exception
    10 
    11         End Try
    12     End Sub

    也可以:

     1     Private Sub ThisWorkbook_Startup() Handles Me.Startup
     2         Try
     3             Dim Selection As Excel.Range = Me.Application.Selection
     4             Dim SelectedRange As Excel.Range = _
     5                 Application.InputBox(Prompt:= _
     6                     "Select the cell or cells to add random value.", _
     7                     Title:="random values", _
     8                     [Default]:=Selection.Address, Type:=8)
     9             SelectedRange.Value = "=rand()"
    10         Catch ex As Exception
    11 
    12         End Try
    13     End Sub

     4. 函数创建及调用

     1     Private Sub ThisWorkbook_Startup() Handles Me.Startup
     2         Try
     3             Dim i As Double
     4             Dim Selection As Excel.Range = Me.Application.Selection
     5             Dim SelectedRange As Excel.Range = _
     6                 Application.InputBox(Prompt:= _
     7                     "Select the cell or cells to add random value.", _
     8                     Title:="random values", _
     9                     [Default]:=Selection.Address, Type:=8)
    10             i = Rnd()
    11             SelectedRange.Value = myFunction(i)
    12         Catch ex As Exception
    13 
    14         End Try
    15     End Sub
    16 
    17     Function myFunction(ByVal j As Double) As Double
    18         myFunction = 5 * j
    19         Exit Function
    20     End Function
  • 相关阅读:
    NPOIHelper.cs (NPOI 2.1.1)
    使用哈希加盐法来为密码加密【转】
    让普通控件拥有左键移动窗体的功能
    Reflector反编译.NET文件后修复【转】
    SD卡中FAT32文件格式快速入门(图文详细介绍)【转】
    项目管理知识体系指南(PMBOOK指南)(第5版) 阅读摘要
    数学
    位运算小结
    字符串(1)——Detect Capital
    数组和矩阵(3)——Next Greater Element I
  • 原文地址:https://www.cnblogs.com/igor/p/4221545.html
Copyright © 2011-2022 走看看