我有這個函數,它可以根據可用庫存計算某些產品的建議價格,現在它不重要,但它以某種方式運行,而我的程序運行速度更快,沒有它我真的很困惑,我不知道爲什麼它很慢VB.net你會如何提高這個功能的性能
Dim MinPrice As Double
Dim VAT = 1.1899999999999999
Dim margin1
Dim potherrule1 As String
Dim margin2
Dim potherrule2 As String
Dim margin3
Dim potherrule3 As String
Dim defaultmargin
If SupplierMargin IsNot Nothing Then
margin1 = SupplierMargin(0)
potherrule1 = SupplierPother(0)
margin2 = SupplierMargin(1)
potherrule2 = SupplierPother(1)
margin3 = SupplierMargin(2)
potherrule3 = SupplierPother(2)
defaultmargin = SupplierMargin(3)
End If
If IsDBNull(CurrentPother) Or (potherrule1 = "x" And potherrule2 = "x" And potherrule3 = "x") Then
MinPrice = Math.Round((oprice/(1 - defaultmargin)) * VAT, 2)
Return MinPrice
End If
If Not IsDBNull(CurrentPother) Then
If potherrule1 <> "x" Then
Dim v1 As Integer
Dim v2 As Integer
Dim rule As String = potherrule1
Dim parts() As String = rule.Split(New String() {" bis "}, StringSplitOptions.None)
v1 = Integer.Parse(parts(0))
v2 = Integer.Parse(parts(1))
If CurrentPother >= v1 And CurrentPother <= v2 Then
MinPrice = Math.Round((oprice/(1 - margin1)) * VAT, 2)
End If
Return MinPrice
ElseIf potherrule2 <> "x" Then
Dim v1 As Integer
Dim v2 As Integer
Dim rule As String = potherrule2
Dim parts() As String = rule.Split(New String() {" bis "}, StringSplitOptions.None)
v1 = Integer.Parse(parts(0))
v2 = Integer.Parse(parts(1))
If CurrentPother >= v1 And CurrentPother <= v2 Then
MinPrice = Math.Round((oprice/(1 - margin2)) * VAT, 2)
Return MinPrice
End If
ElseIf potherrule2 <> "x" Then
Dim v1 As Integer
Dim v2 As Integer
Dim rule As String = potherrule3
Dim parts() As String = rule.Split(New String() {" bis "}, StringSplitOptions.None)
v1 = Integer.Parse(parts(0))
v2 = Integer.Parse(parts(1))
If CurrentPother >= v1 And CurrentPother <= v2 Then
MinPrice = Math.Round((oprice/(1 - margin3)) * VAT, 2)
Return MinPrice
End If
Else
MinimumPriceWhenPother4IsDBnull(SupplierMargin, oprice)
End If
End If
你可以請建議一些改進,可以使此功能更快?
將'Option Strict'設置爲on,避免'ArrayList',而不是'SupplierMargin'使用'List(Of Double)','SupplierPother'使用'List(Of String)'。 –
我發送到這個函數arraylist保存在My.Setting我似乎無法找到'System.Collections.Generic.List(Of Double)'在My.Settings – user1570048
@ user1570048:好的,但即使這樣仍然有可能。 http://stackoverflow.com/questions/951876/can-you-have-a-generic-listof-t-in-your-settings-file –