vb.net编程过程中经验总结-1

前端之家收集整理的这篇文章主要介绍了vb.net编程过程中经验总结-1前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

1.实体类中变量及属性命名

'产品ID
Private _productid As String

Public Property productid() As String
Get
Return _productid
End Get
Set(ByVal value As String)
_productid = value.Trim
End Set
End Property

注:property的名称尽量与db 中字段名相同,这样就可以免去在sql.xml中定义resultmap的麻烦

2.实体类继承父类
Public Class InputOfSaleBean

'继承父类DummymanBean
InheritsDummymanBean

'日期
Private _mdate As String
'销售量
Private _quantity As Integer
'产品名称
Private _pname As String

3.二维数组
Private product(,) As Object = {{"x-S",10},_
{"x-O",{"To",{"Tob",_
{"Tra",5},{"A",{"Te",_
{"Sys",{"P",{"E",10}}

' 产品及该产品的每月的销售情况(10种产品,12个月)
Dim saleInMonth(UBound(product,1),monthCount - 1) As Object

注:UBound(product,1)=9,monthCount - 1=11
则创建的数组saleInMonth[0~9][0~11]
即:vb.net中定义数组的维数时,设定的是该维的item的最大index

4.For循环
For k = 0 To temp.Count - 1 Step 1
Dim outputOfSale As OutputOfSaleBean
outputOfSale = temp.Item(k)
outputOfSale.saledate = saledate
Next k

注:To 相当于小于等于,所以需要减1

5.属性的set设定
' 设定月份
input.mdate = saledate

注:定义类的属性设定参见以上"实体类中变量及属性命名"部分


6.try…catch
' 属性copy
Try
Common.setBeanValue(dummyman,data)
Catch ex As Exception
MsgBox("Common.setBeanValue()'s using is wrong!! ")
End Try

7.函数结束,返回数组
Dim result(1) As Object
result(0) = numAndSale
result(1) = numberOfPYEnd
Return result

注:vb.net中定义数组的维数时,设定的是该维的item的最大index 8.跳出for循环 For m = 0 To lastMonthSize - 1 Step 1 Dim tmpOutputOfSaleBean As OutputOfSaleBean tmpOutputOfSaleBean = lastMonth.Item(m) lastMonthKey = tmpOutputOfSaleBean.key.Trim ' 判断后一个月进药医院中key是否存在与PYEnd中 If currentMonthKey.Equals(lastMonthKey) Then repeatedFlag = True Exit For End If Next m

原文链接:https://www.f2er.com/vb/259832.html

猜你在找的VB相关文章