Überlauffehler 6
03.08.2020 12:06:23
Angelo
ich habe ein Makro geschrieben, dass mir über eine Userform ein Modell der Warteschlangentheorie ausrechnet. Leider bekomme ich in der markierten Zeile x = (r ^ k1) / k_fak einen Überlauffehler, obwohl ich extra alles als Variante aufgrund der u.a. großen Zahlen bei Fakultäten deklariere. Bei kleineren Zahlen läuft das Programm wunderbar.
Private Sub btc_canc_Click()
form_data.txt_ankunft.Value = ""
form_data.txt_bedien.Value = ""
form_data.txt_station.Value = ""
form_data.txt_kapaz.Value = ""
Unload Me
End Sub
Private Sub btn_calc_Click()
'Eingabe durch Benutzer auf Plausibilität prüfen
Dim ctrl As Object
For Each ctrl In form_data.Controls
If TypeName(ctrl) = "TextBox" Then
If ctrl.Value = "" Then
MsgBox ("Bite alle Felder ausfüllen!"), vbCritical
ctrl.SetFocus
Exit Sub
ElseIf Not IsNumeric(ctrl.Value) Then
MsgBox ("Bitte nur Zahlenwerte eingeben!"), vbCritical
ctrl.SetFocus
ctrl.SelStart = 0
ctrl.SelLength = Len(ctrl.Text)
Exit Sub
End If
End If
Next
'Werte aus Eingabefeld auslesen
l = CDbl(form_data.txt_ankunft.Value)
m = CDbl(form_data.txt_bedien.Value)
c = CDbl(form_data.txt_station.Value)
n = CDbl(form_data.txt_kapaz.Value)
Dim t As Variant
Dim k_fak As Variant
Dim c_fak As Variant
Dim r As Variant
Dim rc As Variant
Dim c_fak_ind As Variant
Dim y As Variant
Dim x As Variant
Dim k1 As Variant
Dim k2 As Variant
Dim sum1 As Variant
Dim sum2 As Variant
Dim p0 As Variant
'Eingabefeld nach Übergabe leeren
form_data.txt_ankunft.Value = ""
form_data.txt_bedien.Value = ""
form_data.txt_station.Value = ""
form_data.txt_kapaz.Value = ""
'Eingabefeld schließen
form_data.Hide
'Defintion neuer Variablen für weitere Berechnung
t = c - 1 'neue Variable für c-1
k_fak = 1 'Wert für k!
c_fak = 1 'Wert für c!
r = (l / m) 'Auslastung roh
rc = l / (c * m) 'Auslastung in Abhängigkeit von c
c_fak_ind = 1 'Wert für c! unabhängig von Laufvariable
'p0 Übergangswahrscheinlichkeit
For k1 = 0 To t 'Schleife für aufsummieren des Summenzeichens
k_fak = k_fak * k1
If k_fak = 0 Then 'verhindert Division durch 0
k_fak = 1 'definiert 0! = 1
End If
x = (r ^ k1) / k_fak 'x = 1. Summenzeichen
sum1 = sum1 + x
Next
'c! ausrechnen und vorbereiten für 2. Summeszeichen
For j = 1 To c
c_fak = c_fak * j
Next
For k2 = c To n 'Schleife für aufsummieren des Summenzeichens
y = (r ^ k2) / ((c ^ (k2 - c)) * c_fak) 'y = 2. Summenzeichen
sum2 = sum2 + y
Next
p0 = (sum1 + sum2) ^ -1
'pn
For i = 1 To c 'Schleife für c!
c_fak_ind = c_fak_ind * i
Next
pn = p0 * (r ^ n / (c_fak_ind * (c ^ (n - c))))
test = (c_fak_ind * (c ^ (n - c)))
test2 = (r ^ n)
'lw durchsch. Warteschlangenlänge
lw1 = p0 * (((r ^ c) * rc) / (c_fak_ind * ((1 - rc) ^ 2)))
lw2 = 1 - (rc ^ (n - c + 1)) - (1 - rc) * (n - c + 1) * (rc ^ (n - c))
lw = lw1 * lw2 'Formel aufgeteilt aufgrund der Länge
'ae durchsch. Anzahl Elemente im System
ae = lw + r * (1 - pn)
've durchsch. Verweilzeit eines Elements im System
ve = ae / (l * (1 - pn))
'we durchsch. Wartezeit eines Elements
we = ve - (1 / m)
'Datenrückgabe an Tabelle - übergebene Daten
Cells(Cells(Rows.Count, "A").End(xlUp).Row + 1, "A").Value = l
Cells(Cells(Rows.Count, "B").End(xlUp).Row + 1, "B").Value = m
Cells(Cells(Rows.Count, "C").End(xlUp).Row + 1, "C").Value = c
Cells(Cells(Rows.Count, "D").End(xlUp).Row + 1, "D").Value = n
Cells(Cells(Rows.Count, "E").End(xlUp).Row + 1, "E").Value = lw
Cells(Cells(Rows.Count, "F").End(xlUp).Row + 1, "F").Value = ae
Cells(Cells(Rows.Count, "G").End(xlUp).Row + 1, "G").Value = ve
Cells(Cells(Rows.Count, "H").End(xlUp).Row + 1, "H").Value = we
Cells(Cells(Rows.Count, "I").End(xlUp).Row + 1, "I").Value = rc
End Sub