指定された期間の分布の期待値を返す関数を作成したいと考えています。入力は次の形式のみになります ExpValue(Jan--01/June30;EXPO(2000),July--01/Dec--31;NORM(1000,2000)) --01/Dec--31 は期間です。また、EXPO(2000) と NORM(1000,2000) は、その特定の季節のデータの分布のタイプ (平均値、標準偏差などを括弧内に示します) です。ユーザーは、分布のタイプとして最初の 4 文字のみを入力する必要があります。たとえば、NORMAL 分布の場合は NORM、EXPONENTIAL 分布の場合は EXPO などです。"," で区切られたできるだけ多くのシーズンと、各シーズンの期間のタイプを入力する必要があります。 「;」で区切られたデュレーションからそれぞれ言及されます。
関数のコードを書きましたが、機能しません。必要な変更を提案してください。
Public Function ExpValue(str As String) As String
Dim Mylen As Integer
Dim A As Integer
Dim B As Integer
Dim C As Integer
Dim D As Integer
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim l As Double
Dim N As Integer
Dim ExpectValue As Double
Dim Arr1() As String
Dim Arr2() As String
Dim Arr3() As String
Dim Arr4() As String
Dim Arr5() As String
Dim Arr6() As String
Dim Arr7() As Double
Dim txt1 As String
Dim txt2 As String
Dim txt3 As String
Dim txt4 As String
Dim txt5 As String
Dim txt6 As String
Arr1() = Split(str, ",")
C = UBound(Arr1())
ReDim Arr1(C) As String
For i = 0 To C
Arr2() = Split(Arr1(i), ";")
ReDim Arr2(1) As String
Arr3(i) = Arr2(0)
Arr4(i) = Arr2(1)
Next i
ReDim Arr3(C) As String
ReDim Arr4(C) As String
For i = 0 To C
txt1 = Arr4(i)
Mylen = Len(txt1)
txt2 = Left(txt1, 4) ' type of distribution
A = Mylen - 5
B = Mylen - 6
txt3 = Right(txt1, A) ' 1,2.3,4,... )
txt4 = Left(txt3, B) ' 1,2.3,4.,..
Arr5 = Split(txt4, ",")
D = UBound(Arr5())
ReDim Arr7(D) As Double
For j = 0 To D
Arr7(i) = CDbl(Arr5(i))
Next j
Select Case txt2
Case "EXPO", "POIS" ' just one number EXPO(2.34)
l = CDbl(txt4) ' txt4=2.34
Arr6(i) = l
Case "NORM"
ExpectValue = Arr7(1)
Arr6(i) = ExpectValue
Case "BETA"
ExpectValue = (Arr7(1) / (Arr7(0) + Arr7(1)))
Arr6(i) = ExpectValue
Case "GAMM"
ExpectValue = Arr7(0) * Arr7(1)
Arr6(i) = ExpectValue
Case "TRIA"
ExpectValue = ((Arr7(0) + Arr7(1) + Arr7(2)) / 3)
Arr6(i) = ExpectValue
Case "UNIF"
ExpectValue = ((Arr7(0) + Arr7(1)) / 2)
Arr6(i) = ExpectValue
Case "LOGN"
ExpectValue = Exp((Arr7(0) + ((Arr7(1)) ^ 2)) / 2)
Arr6(i) = ExpectValue
Case "ERLA"
ExpectValue = Arr7(0) * Arr7(1)
Arr6(i) = ExpectValue
End Select
'Next j
Next i
'i = i + 1
If C = 0 Then
txt6 = Arr3(0) & ";" & Arr6(0)
Else
txt6 = ""
For i = 0 To C
txt6 = txt6 & "," & Arr3(i) & "," & Arr6(i)
Next i
End If
ExpValue = txt5
End Function