我最终做了一个巨大的解决方法,为 values() 和其他 2 个布尔数组的标志创建一个布尔数组,只要 mathEqu() 中的一个方程是可解的(当所有值在一个等式/表达式中不是 0)和另一个帮助设置一个标志(就像我说的,巨大的变通方法)。
以下是我的代码中的大致数学原理:
Public Class NPNpositive
Dim values(15) As Double
Dim i = 0
Dim j As Double = 0
Dim k = 0
Dim l = 0
Dim p = 0
// Whenever you click the calculation-button
Private Sub Calculation_Click(sender As Object, e As EventArgs) Handles Calculation.Click
Dim tbArray() As TextBox = New TextBox() {IB, IC, IE, .. .., URC, hfe}
Dim tbBool() As Boolean = New Boolean() {False, False, False, .. .., False, False}
For Each number In values
If i < 16 Then
If Double.TryParse(tbArray(i).Text, j) Then
values(i) = j
End If
End If
i += 1
j = 0
Next
Dim mathBool As Boolean()() = {
New Boolean() {False, False, False},
New Boolean() {False, False, False},
New Boolean() {False, False},
..,
..,
New Boolean() {False, False}
New Boolean() {False}}
Calculations:
i = 0
j = 0
k = 0
p = 0
// Raising a True-flag if the value in values(i) does not equal 0
For Each n In values
If Not values(i) = 0 Then
tbBool(i) = True
End If
i += 1
Next
// Raising a True-flag when an expression is do-able
Dim mathBoolHelp As Boolean() = {
tbBool(1) And tbBool(15),
tbBool(2) And tbBool(1),
tbBool(3) And tbBool(4),
tbBool(0) And tbBool(15),
tbBool(2) And tbBool(0),
tbBool(14) And tbBool(7),
tbBool(12) And tbBool(8),
..,
..,
tbBool(11) And tbBool(10),
tbBool(1) And tbBool(7),
tbBool(1) And tbBool(0)}
// Here is where the calculations are happening
Dim mathEqu As Double()() = {
New Double() {values(1) / values(15), values(2) - values(1), values(3) - values(4)},
New Double() {values(0) * vlaues(15), values(2) - values(0), values(14) / values(7)},
New Double() {values(12) / values(8), values(0) + values(1)},
..,
..,
New Double() {values(11) - values(10), values(1) * values(7)},
New Double() {values(1) / values(0)}}
i = 0
// This is where things start to look interesting
// The mathBoolHelp puts in flags in the Boolean jagged Array
For Each m in values
j = mathBool(i).Length
For value As Integer = 0 To j - 1
If mathBoolHelp(p) = True Then
mathBool(i)(k) = True
End If
k += 1
p += 1
Next
i += 1
k = 0
Next
i = 0
j = 0
k = 0
// It checks now in the counter-Boolean Array for a True
// If it finds a true at dimension k, column i, in mathBool()(), it calculates
// the number from the same spot, just from mathEqu()() instead
For Each m In values
If values(i) = 0 Then
j = mathEqu(i).Length
For value As Integer = 0 To j - 1
If mathBool(i)(k) = True Then
values(i) = mathEqu(i)(k)
End If
If Not values(i) = 0 Then
GoTo forEnd
End If
k += 1
Next
forEnd:
End If
i += 1
k = 0
Next
这是整个程序的一小部分。主要问题是仅当在数组中的那个位置计算所需的两个/所有值都不为 0 时才计算。我以前的代码就是这样工作的,但是它有 16 个长的 If 语句和各种长度。而且不好看。
我的问题可能有更好的解决方案,所以在那之前,这会很好。