You are on page 1of 4

Public Class Form1

Dim a, b, s As Integer

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


Me.Show()
txtawal.Focus()

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btfor.Click


Dim i As Integer

listhasil.Items.Clear()

a = Val(txtawal.Text)
b = Val(txtakhir.Text)
s = Val(txtstep.Text)

If txtstep.Text = "" Or txtstep.Text = "0" Then


s = 1
MessageBox.Show("Step Tidak boleh kosong atau 0. Minimal Bernilai 1",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtstep.Text = s
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" And txtakhir.Text = "" Then
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" Then
txtawal.Text = a
ElseIf txtakhir.Text = "" Then
txtakhir.Text = b

End If

If a < b Then
If txtstep.Text < 0 Then
s = Val(txtstep.Text) * -1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * 1
End If
txtstep.Text = s
For i = a To b Step s
listhasil.Items.Add(i)
Next

ElseIf a > b Then


If txtstep.Text < 0 Then
s = Val(txtstep.Text) * 1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * -1
End If
txtstep.Text = s
For i = a To b Step s
listhasil.Items.Add(i)
Next
End If
End Sub

Private Sub btdowhile_Click(sender As Object, e As EventArgs) Handles btdowhile.Click

listhasil.Items.Clear()

a = Val(txtawal.Text)
b = Val(txtakhir.Text)
s = Val(txtstep.Text)

If txtstep.Text = "" Or txtstep.Text = "0" Then


s = 1
MessageBox.Show("Step Tidak boleh kosong atau 0. Minimal Bernilai 1",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtstep.Text = s
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" And txtakhir.Text = "" Then
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" Then
txtawal.Text = a
ElseIf txtakhir.Text = "" Then
txtakhir.Text = b

End If

If a < b Then
If txtstep.Text < 0 Then
s = Val(txtstep.Text) * -1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * 1
End If
txtstep.Text = s
Do While (a <= b)
listhasil.Items.Add(a)
a += s
Loop

ElseIf a > b Then


If txtstep.Text < 0 Then
s = Val(txtstep.Text) * 1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * -1
End If
txtstep.Text = s
Do While (a >= b)
listhasil.Items.Add(a)
a += s

Loop
End If
End Sub
Private Sub btwhile_Click(sender As Object, e As EventArgs) Handles btwhile.Click
listhasil.Items.Clear()

a = Val(txtawal.Text)
b = Val(txtakhir.Text)
s = Val(txtstep.Text)

If txtstep.Text = "" Or txtstep.Text = "0" Then


s = 1
MessageBox.Show("Step Tidak boleh kosong atau 0. Minimal Bernilai 1",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtstep.Text = s
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" And txtakhir.Text = "" Then
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" Then
txtawal.Text = a
ElseIf txtakhir.Text = "" Then
txtakhir.Text = b
End If

If a < b Then
If txtstep.Text < 0 Then
s = Val(txtstep.Text) * -1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * 1
End If

txtstep.Text = s
While (a <= b)
listhasil.Items.Add(a)
a += s
End While

ElseIf a > b Then


s = Val(txtstep.Text) * -1
txtstep.Text = s
While (a >= b)
listhasil.Items.Add(a)
a += s
End While
End If
End Sub

Private Sub btdountil_Click(sender As Object, e As EventArgs) Handles btdountil.Click


listhasil.Items.Clear()

a = Val(txtawal.Text)
b = Val(txtakhir.Text)
s = Val(txtstep.Text)

If txtstep.Text = "" Or txtstep.Text = "0" Then


s = 1
MessageBox.Show("Step Tidak boleh kosong atau 0. Minimal Bernilai 1",
"Informasi", MessageBoxButtons.OK, MessageBoxIcon.Information)
txtstep.Text = s
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" And txtakhir.Text = "" Then
txtawal.Text = a
txtakhir.Text = b
ElseIf txtawal.Text = "" Then
txtawal.Text = a
ElseIf txtakhir.Text = "" Then
txtakhir.Text = b
End If

If a < b Then
If txtstep.Text < 0 Then
s = Val(txtstep.Text) * -1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * 1
End If

txtstep.Text = s

Do Until a > b
listhasil.Items.Add(a)
a += s
Loop
ElseIf a > b Then
If txtstep.Text < 0 Then
s = Val(txtstep.Text) * 1
ElseIf txtstep.Text > 0 Then
s = Val(txtstep.Text) * -1
End If
txtstep.Text = s
Do Until a < b
listhasil.Items.Add(a)
a += s
Loop
End If

End Sub

End Class

Thank regard

Om toto :D

You might also like