VisualBasic2010_Syntax

12 篇文章 0 订阅
1 篇文章 0 订阅
Visual Basic 2010

声明
  变量声明
    [attribute_list] [accessibility] [Shared] [Shadows] [ReadOnly] _
    Dim [WithEvents] name [(bound_list)] [As [New] type] _
    [= initialization_expression]
    Accessibility
      Public|Protected|Friend|Protected Friend|Private|Static
  枚举类型
    [attribute_list] [accessibility] [Shadows] Enum name [As type] _
      [attribute_list] value_name [= initialization_expression]
      [attribute_list] value_name [= initialization_expression]
      ...
    End Enum
  Nullable类型
    Dim i As Integer?,Dim j? As Integer,Dim k As Nullable(Of Integer)
  常量声明
    [attribute_list] [accessibility] [Shadows] _
	Const name [As type] = initialization_expression
  Option Explicit|Infer|Strict On|Off
数据类型Data Types
  Boolean
  Byte,SByte
  Char|c
  Short|S,UShort|US
  Integer|I,UInteger|UI
  Long|L,ULong|UL
  Single|F,Double|R
  Decimal|D
  String
  Date
  Object
  Structure
  Nothing
  类型字符
    %,Integer;&,Long;@,Decimal;!,Single;#,Double;$,String
  进制转换
    Hex,Oct()
  类型转换
    CBool,CByte,CChar,CDate,CDbl,CDec,CInt,CLng,CObj,CSByte,CShort,CSng,CStr,CUInt,CULng,CUShort
    [Integer].Parse
    DataType.TryParse(,),Val()
    Convert.[ToDecimal(),ToInt32]
    numVal.ToString(formatString)
      C|c,Currency;N|n,Number;F|f,Fixed-Point;P|p,Percent
    Financial.Pmt(Rate,NPer,PV)
输入输出
  InputBox(prompt[,title][,defaultResponse])
  MessageBox.Show(text,caption,buttons,icon[,defaultButton])
操作符Operators
  算术操作符
    +-*/ Mod ^ \整数除法 << >>
	数学函数
      Abs,Atan,Cos,Exp,Sign,Sin,Sqrt,Tan
      'Imports System.Math
  连接操作符
    &
  比较操作符
    = <> > < >= <= Is IsNot TypeOf..Is Like
	Like:?,*,#[][!]A-Z
  逻辑操作符
    And/AndAlso Or/OrElse Not Xor
  位操作符
    Not And Or Xor
  赋值操作符
    = += -= /= ^= \= &= <<= >>= *=
  操作符重载
    [<attributes>] Public [Overloads] Shared [Shadows] _
	[Widening|Narrowing] Operator symbol(operands) As type
流程控制
  条件
    单行If Then
	  If condition Then statement
	多行If Then
	  If condition1 Then
	    statements1
	  ElseIf condition2
	    statements2
	  ...
	  Else
	    statements3
	  End If
	选择
	  Select Case test_value
	    Case comparison_expression1
		  statements1
		Case comparison_expression2
		  statements2
		...
		Case Else
		  else_statements
	  End Select
	  Case语句
	    Case comparison_expression
		Case 1 To 10
		Case Is <= 10
		Case 'a','b','c'
		Case Enum_value
	IIf
	  variable = IIf(condition, value_if_true, value_if_false)
	If
	Choose
	  variable = Choose(index, value1, value2, ...)
  循环
    For Next
	  For variable [As data_type] = start_value To stop_value [Step increment]
	    statemnts
		[Exit For]
		statements
		[Continue For]
		statements
	  Next [variable]
    For Each
	  For Each variable [As object_type] In group
	    statements
		[Exit For]
		statements
		[Continue For]
		statements
	  Next [variable]
	  IEnumerable接口实现类
	    Array,ArrayList,Collection,CollectionBase,ControlCollection,DataView,DictionaryBase,DictionaryEntries,Hashtable
		HybridDictionary,ListDictionary,MessageQueue,OdbcDataReader,OleDbDataReader,OracleDataReader,Queue,ReadOnlyCollectionBase,SortedList
		SqlDataReader,Stack,String,StringCollection,StringDictionary,TableCellCollection,TableRowCollection,XmlNode,XmlNodeList
    Do Loop
	  Do
	    statements
	    [Exit Do]
	    statements
	    [continue Do]
	    statements
	  Loop
	  Do {While|Until} condition
	    statements
		[Exit Do]
		statements
		[Continue Do]
		statements
	  Loop
	  Do
	    statements
		[Exit Do]
		statements
		[Continue Do]
		statements
	  Loop {While|Until} condition
	While End
	  While condition
	    statements
		[Exit While]
		statements
		[Continue While]
		statements
	  End While
	  Do While condition
	    statements
		[Exit Do]
		statements
		[Continue Do]
		statements
	  Loop
	Exit,Continue,Goto
  异常
    Try
	  try_statements
	[Catch ex As exception_type_1
	  exception_statements_1
	] ...
	[Catch
	  finally_exception_statements
	]
	[Finally
	  finally_statements
	]
	End Try
    Exit Try
    ArgumentException,ArgumentOutOfRangeException
    ArithmeticException
    DataException
    DiretoryNotFoundException
    DivideByZeroException
    EndOfStreamException
    Exception
    FileNotFoundException
    IndexOutOfRangeException
    IOException
    OutOfMemoryException
    OverFlowException
    SecurityException
    SqlException
    UnauthorizedAccessException
类与对象Object,Class
  类
	  [attribute_list] [Partial] [accessibility] [Shadows] [inheritance] _
	  Class name [(Of type_list)]
		[Inherits parent_class]
		[Implements interface]
		statements
	  End ClASS
  结构Structure
	  [attribute_list] [Partial] [accessibility] [Shadows] _
	  Structure name[(Of type_list)]
		[Implements interface]
		statements
	  End Structure
  事件Event
    [attribute_list] [accessibility] [Shadows] _
	Event event_name([paremeters]) [Implements interface.event]
  用户事件Custom Event
    [attribute_list] [accessibility] [Shadows] _
	Custom Event event_name As delegate_name [Implements inteface.event]
	  [attribute_list] AddHandler(ByVal value As delegate_name)
	    ...
	  End AddHandler
	  [attribute_list] RemoveHandler(ByVal value As delegate_name)
	    ...
	  End RemoveHandler
	  [attribute_list] RaiseEvent(delegate_signature)
	    ...
	  End RaiseEvent
	End Event
  Public [ReadOnly|WriteOnly] Property..As..
    Get
      Return
    End Get
    Set(ByVa..As..)
    End Set
  End Property
  构造函数 Public Sub New()..End Sub
模块Module
过程Procedure
  函数过程Function
    [attribute_list] [inheritance_mode] [aceesibility] _
	Function function_name([parameters]) [As return_type] [Implements interface.function]
	  [statements]
	End Function
  子过程Subroutine
    [attribute_list] [inheritance_mode] [accessbility] _
	Sub subroutine_name([parameters]) [Implements interface.subroutine]
	  [statements]
    End Sub
    inheritance_mode:Overloads,Overrides,Overridable,NotOverridable,MustOverride
名字空间Namespace
  My.(Application,Computer,Forms,Resources,Settings,User,WebServices)
  导入Imports
    Imports [alias=] namespace[.element]
集合类Collection Classes
  数组Array
    [Dim|Private|Static]..(.To.,.To.,..)As..
    [Dim|Private|Static]..()(.To.,.To.,..)As..={initValue}
    Array.Reverse,Sort,BinarySearch
  集合Collections
    ArrayList
	  Add,AddRange,BinarySearch,Capacity,Clear,Contains,CopyTo,
	  Count,GetRange,IndexOf,Insert,InsertRange,Item,LastIndexOf
	  Remove,RemoveAt,RemoveRange,Reverse,SetRange,Sort,ToArray,TrimToSize
字符串及文件处理
  StreamReader,StreamWriter,Imports System.IO
  My.Computer.FileSystem.(ReadAllText,WriteAllText)
  String.(ToUpper,ToLower,Length,Contains,Substring,IndexOf,Trim,
          Remove,Insert,Compare,CompareTo,Replace,StartsWith,EndsWith,
          PadLeft,PadRight,Split)
  Asc,Chr
  string Like pattern, ? . #(any digit) [charList]
  [Dim|Private]..As IO.StreamWriter
  [Dim|Private]..As IO.StreamReader
  IO.File.,IO.File.OpenText,IO.File.Exists
  .Write|WriteLine,.Close()
  .ReadLine,.Peek,.Close
控件Controls
  (Pointer),BackgroundWorker,BindingNavigator,BindingSource,Button,CheckBox,CheckedListBox,ColorDialog,ComboBox,ContextMenuStrip
  DataGridView,DataSet,DateTimePicker,DiretoryEntry,DiretorySearcher,DomainUpDown,ErrorProvider,EventLog,FileSystemWatcher,FlowLayoutPanel
  FolderBrowserDialog,FontDialog,GroupBox,HelpProvider,HScrollBar,ImageList,Label,LinkLabel,ListBox,ListView
  MaskedTextBox,MenuStrip,MessageQueue,MonthCalendar,NotifyIcon,NumericUpDown,OpenFileDialog,PageSetupDialog,Panel,PerformanceCounter
  PictureBox,PrintDialog,PrintPreviewDialog,PrintPreviewControl,PrintDocument,Process,ProgressBar,PropertyGrid,RadioButton,RichTextBox
  SaveFileDialog,SerialPort,ServiceController,SplitContainer,Splitter,StatusStrip,TabControl,TableLayoutPanel,TextBox,Timer
  ToolStrip,ToolStripContainer,ToolTip,TrackBar,TreeView,VScrollBar,WebBrowser
  对话框Dialogs
    ColorDialog,FolderBrowserDialog,FontDialog,OpenFileDialog
    PageSetupDialog,PrintDialog,PrintPreviewDialog,SaveFileDialog
  控件大小Size
    Bounds,ClientRectangle,ClientSize,DisplayRectangle,Location,Size,Left,Top,Width,Height,Bottom,Right
  WPF控件
    容器
      Border,BulletDecorator,Canvas,DockPanel,Expander,Grid,GridSplitter,GridView,GroupBox
      Panel,ScrollViewer,Separator,StackPanel,TabControl,TabItem,Viewbox,VirtualizingStackPanel
      WrapPanel
    选择
      CheckBox,ComboBox,ComboBoxItem,ListBox,ListBoxItem,RadioButton,ScrollBar,Slider
    输入
      PasswordBox,RichTextBox,TextBox
    显示
      Label,TextBlock,TreeView
    反馈
      Popup,ProgressBar,StatusBar,StatusBarItem,ToolTip
    初始
      Button,ContextMenu,Menu,MenuItem,PrintDialog,RepeatButton,ToolBar,ToolBarTray
    图形媒体
      Ellipse,Image,Line,MediaElement,Path,Polygon,Polyline,Rectangle
    文档
      DocumentViewer,FlowDocumentPageViewer,FlowDocumentReader,FlowDocumentScollViewer
    Ink
      InkCanvas,InkPresenter
文件结构
  Option语句
    Option Explicit On, Option Strict Off, Option Compare Binary, Option Infer On
  Imports语句
  Main子程序
  Class,Module,Namespace语句
代码折叠
  #Region..#End Region
条件编译
  #If..Then..#ElseIf..Then..#Else..#End If
  设置常量
    #Const
  预定义常量
    CONFIG,DEBUG,PLATFORM,TARGET,TRACE,VBC_VER,_MyType
名称空间
  Namespace..End Namespace
注释
  单行注释,'
  多行注释,#IF False Then..#End If
  XML注释,'''
续行
  _
代码合并到一行
  :
行标号
  label:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值