VB语法
1、For循环
For i As Integer = 0 To pTable.Fields.FieldCount - 1 Next
2、Select语句
Dim pFeatLyr As IFeatureLayer = pLayer Select pFeatLyr.FeatureClass.ShapeType Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPoint : Return "Point" Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolygon : Return "Polygon" Case ESRI.ArcGIS.Geometry.esriGeometryType.esriGeometryPolyline : Return "Polyline" End Select
3、自定义类
Public Class RiverData Dim m_riverName As String Public Property RiverName Get Return m_riverName End Get Set(ByVal value) m_riverName = value End Set End Property End Class
4、单利模式
Public Shared Function Getinstance(ByVal AssetApplication As AssetApplication) As PropertyQueryFrom If PQfrom Is Nothing OrElse PQfrom.IsDisposed Then PQfrom = New PropertyQueryFrom PQfrom.m_AssetApplication = AssetApplication End If Return PQfrom End Function
5、获取枚举的类型
enumPipeMaterial.钢管.GetType()
6、计算时间差
Private Function CoutTime(ByVal oldtime As DateTime, ByVal newtime As DateTime) As Integer Dim ts1 As TimeSpan = New TimeSpan(oldtime.Ticks) Dim ts2 As TimeSpan = New TimeSpan(newtime.Ticks) Dim ts3 As TimeSpan = ts1.Subtract(ts2).Duration() Return ts3.Days / 365 End Function
7、类型转换
TryCast(pLayer, IFeatureLayer) '转换失败返回Nothing CType(pLayer, IFeatureLayer) '转换失败报错
8、Linq
Dim query As IEnumerable(Of Data) = historyDataObj.Where(Function(x) x.DataID = dataId) For Each item As Data In query Next
如果 historyDataObj 数组有Nothing 空值的话,上面的代码会出现问题,需要自定义函数判断,修改后的代码如下:
过滤的代码:
Dim query As IEnumerable(Of RealData) = historyDataObj.Where(Function(x) CheakData(x, dataId))
过滤函数:
Private Function CheakData(ByVal item As RealData, ByVal dataid As String) As Boolean If IsNothing(item) Then Return False Else Return item.DataID = dataid End If End Function
9、计算时差
Private Function CoutTime(ByVal oldtime As DateTime) As String Dim ts1 As TimeSpan = New TimeSpan(oldtime.Ticks) Dim ts2 As TimeSpan = New TimeSpan(DateTime.Now.Ticks) Dim ts3 As TimeSpan = ts1.Subtract(ts2).Duration() Return ts3.Seconds & "秒" & ts3.Milliseconds & "毫秒" End Function
10、生成txt并写入文本
Dim str As StreamWriter = File.AppendText("e:\\Alarmlog2.txt") str.WriteLine(Date.Now.ToString()) str.Flush() str.Close()
11、三目运算
Dim strResult As String strResult = IIf(2 < 4, "yes", "no")
12、定义一维数组
Dim ss(2) As Object
posted on 2016-03-21 18:57 Geography爱好者 阅读(407) 评论(0) 编辑 收藏 举报