Hi everyone!
I'm a beginner at VB and am trying to make a very simple program. I'm very sure that my code is inelegant and inefficient, but please bear with me.
Here is a portion of my code. I've tried to make it as short as possible, but it's still quite long (I omitted '1/3 4 sets of 2' because there are no problems there and 2/3 and 3/3 are very much the same). However, the code crashes at this line, the second line of 3/3:
aTw(9, 0) = b2 * c2
The error message I get is "An unhandled exception of type 'System.IndexOutOfRangeException' occurred." I'm not sure why this happens since the code is practically the same as before. When I tried to remove that line, the same error occured at "aTw(10, 0) = b2 - c2" so I'm assuming the first index for aTw can't exceed 8, which is weird because it should go up to 11.
Thank you very much and sorry again for the super long code.
Dim a, b, c, d, a2, b2, c2, a3, b3, all As Integer
Dim aTh(23, 2), aTw(11, 1) As Integer
Dim statement(287, 1), holder As String
Dim flip As Boolean = False
For i As Integer = 0 To 23
a2 = aTh(i, 0)
b2 = aTh(i, 1)
c2 = aTh(i, 2)
'2/3 4 sets of 2'
aTw(4, 0) = a2 + c2
aTw(4, 1) = b2
holder = statement(i * 12 + 4, 1)
statement(i * 12 + 4, 1) = "(" & holder & " + " & c2 & ")"
aTw(5, 0) = a2 * c2
aTw(5, 1) = b2
holder = statement(i * 12 + 5, 1)
statement(i * 12 + 5, 1) = "(" & holder & " * " & c2 & ")"
If a2 > c2 Then
aTw(6, 0) = a2 - c2
Else
aTw(6, 0) = c2 - a2
flip = True
End If
aTw(6, 1) = b2
holder = statement(i * 12 + 6, 1)
If flip = False Then
statement(i * 12 + 6, 1) = "(" & holder & " - " & c2 & ")"
Else
statement(i * 12 + 6, 1) = "(" & c2 & " - " & holder & ")"
flip = False
End If
If a2 = c2 Then
aTw(7, 0) = 1
ElseIf a2 > c2 Then
If (a2 Mod c2) = 0 Then
aTw(7, 0) = a2 / c2
Else
aTw(7, 0) = 2311
End If
Else
If (c2 Mod a2) = 0 Then
aTw(7, 0) = c2 / a2
flip = True
Else
aTw(7, 0) = 2311
End If
End If
aTw(7, 1) = b2
holder = statement(i * 12 + 7, 1)
If flip = False Then
statement(i * 12 + 7, 1) = "(" & holder & " / " & c2 & ")"
Else
statement(i * 12 + 7, 1) = "(" & c2 & " / " & holder & ")"
flip = False
End If
'3/3 4 sets of 2'
aTw(8, 0) = b2 + c2
aTw(8, 1) = a2
statement(i * 12 + 8, 2) = "(" & b2 & " + " & c2 & ")"
aTw(9, 0) = b2 * c2
'The code crashes here'
aTw(9, 1) = a2
statement(i * 12 + 9, 2) = "(" & b2 & " * " & c2 & ")"
If b2 > c2 Then
aTw(10, 0) = b2 - c2
Else
aTw(10, 0) = c2 - b2
flip = True
End If
aTw(10, 1) = a2
If flip = False Then
statement(i * 12 + 10, 2) = "(" & b2 & " - " & c2 & ")"
Else
statement(i * 12 + 10, 2) = "(" & c2 & " - " & b2 & ")"
flip = False
End If
If b2 = c2 Then
aTw(11, 0) = 1
ElseIf b2 > c2 Then
If (b2 Mod c2) = 0 Then
aTw(11, 0) = b2 / c2
Else
aTw(11, 0) = 2311
End If
Else
If (c2 Mod b2) = 0 Then
aTw(11, 0) = c2 / b2
flip = True
Else
aTw(11, 0) = 2311
End If
End If
aTw(11, 1) = a2
If flip = False Then
statement(i * 12 + 11, 2) = "(" & b2 & " / " & c2 & ")"
Else
statement(i * 12 + 11, 2) = "(" & c2 & " / " & b2 & ")"
flip = False
End If