Katsotaan, onko kelvollinen lukujono ja asetetaan loppu lukujono.
Public Class Form1
Dim luvut(8) As Double
Dim maara = 0
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
'Asetetaan luvut
luvut(0) = 0
luvut(1) = 0
luvut(2) = 0
luvut(3) = 0
luvut(4) = 0
luvut(5) = 0
luvut(6) = 0
luvut(7) = 0
'Määritellään lukujonon pituus.
If (Not TextBox1.Text = "") Then
luvut(0) = Double.Parse(TextBox1.Text)
maara = maara + 1
If (Not TextBox2.Text = "") Then
luvut(1) = Double.Parse(TextBox2.Text)
maara = maara + 1
If (Not TextBox3.Text = "") Then
luvut(2) = Double.Parse(TextBox3.Text)
maara = maara + 1
If (Not TextBox4.Text = "") Then
luvut(3) = Double.Parse(TextBox4.Text)
maara = maara + 1
If (Not TextBox5.Text = "") Then
luvut(4) = Double.Parse(TextBox5.Text)
maara = maara + 1
If (Not TextBox6.Text = "") Then
luvut(5) = Double.Parse(TextBox6.Text)
maara = maara + 1
If (Not TextBox7.Text = "") Then
luvut(6) = Double.Parse(TextBox7.Text)
maara = maara + 1
If (Not TextBox8.Text = "") Then
luvut(7) = Double.Parse(TextBox8.Text)
maara = maara + 1
End If
End If
End If
End If
End If
End If
End If
End If
Dim perustulo As Double
Dim perussumma(10) As Double
Dim onkoPerustulo As Boolean = True
Dim onkoPerussumma(10) As Boolean 'Kuinka monen kertaiseksi summa kasvaa.
If (maara >= 2) Then
perustulo = luvut(1) / luvut(0)
For x = 0 To 10
onkoPerussumma(x) = True
perussumma(x) = luvut(1) - luvut(0)
Next x
End If
'Katsotaan, millainen lukujonosta tulee.
Dim i = 1
While (i < 7 And i < maara)
If (perustulo <> luvut(i) / luvut(i - 1)) Then
onkoPerustulo = False
End If
For y = 0 To 9
If (perussumma(y) <> luvut(i) - luvut(i - 1)) Then
onkoPerussumma(y) = False
End If
perussumma(y) = perussumma(y) * (y + 1)
Next y
i += 1
End While
'Etsitään perussumma.
Dim j = 0
Dim onkoPerus = False
If (onkoPerussumma(0) = True) Then
onkoPerus = True
End If
While (j < 9 And onkoPerussumma(j) = False)
j = j + 1
If (onkoPerussumma(j) = True) Then
onkoPerus = True
End If
End While
'Muodostetaan loppujono.
While (i < 8)
If (onkoPerustulo) Then
luvut(i) = luvut(i - 1) * perustulo
ElseIf (onkoPerus) Then
luvut(i) = luvut(i - 1) + perussumma(j)
perussumma(j) = perussumma(j) * (j + 1)
End If
i += 1
End While
'Näytetään luvut.
TextBox1.Text = luvut(0).ToString
TextBox2.Text = luvut(1).ToString
TextBox3.Text = luvut(2).ToString
TextBox4.Text = luvut(3).ToString
TextBox5.Text = luvut(4).ToString
TextBox6.Text = luvut(5).ToString
TextBox7.Text = luvut(6).ToString
TextBox8.Text = luvut(7).ToString
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
'Tyhjennetään
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
maara = 0
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
'Asetaan leikepöydälle.
Dim tulos As String = ""
For x = 0 To 7
tulos += luvut(x).ToString() + " "
Next x
Clipboard.SetText(tulos)
End Sub
End ClassAihe on jo aika vanha, joten et voi enää vastata siihen.