Jumat, 30 November 2012
TUTORIAL PROGRAM PERSAMAAN KUADRAT
TUTORIAL PERSAMAAN
KUADRAT
1.
Buka visual basic 2010 lalu pilih new
project dan pilih windows form application.
2.
Masukkan beberapa label, textbox, dan
button untuk keperluan program.
3.
Textbox1,textbox2, dan textbox3
digunakan untuk menulis persamaan kuadrat yang ingin dicari akar-akarnya.
4.
Textbox4 dan textbox5 untuk memunculkan
akar-akar berlainan, textbox6 dan textbox7 untuk memunculkan akar kembar, dan
textbox8 dan textbox9 untuk memunculkan akar tidak real.
5.
Button1 (calculate) digunakan untuk menghitung
akar-akar dari persamaan kuadrat. Masukkan listing sebagai berikut :
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
Dim var_a, var_b, var_c, var_D, var_x1, var_x2 As Single
var_a
= TextBox1.Text
var_b
= TextBox2.Text
var_c = TextBox3.Text
(menempatkan variabel a,b,c di textbox yang
diinginkan (textbox1,2,3))
var_D
= var_b ^ 2 - (4 * var_a * var_c)
(digunakan untuk menghitung nilai
diskriminan)
If var_D > 0 Then
var_x1 = (-var_b + Math.Sqrt(var_D))
/ 2 * var_a
var_x2 = (-var_b - Math.Sqrt(var_D))
/ 2 * var_a
TextBox4.Text = var_x1
TextBox5.Text = var_x2
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
(digunakan
untuk menghitung akar-akar yang berlainan dan
memunculkannya di textbox yang ditentukan (textbox4dan5))
ElseIf var_D = 0 Then
var_x1 = -var_b / 2 * var_a
var_x2 = -var_b / 2 * var_a
TextBox6.Text = var_x1
TextBox7.Text = var_x2
TextBox4.Clear()
TextBox5.Clear()
TextBox8.Clear()
TextBox9.Clear()
(digunakan
untuk menghitung akar-akar kembar dan memunculkannya di textbox yang ditentukan
(textbox6dan7))
Else
TextBox8.Text = "Akar tidak real"
TextBox9.Text = "Akar tidak real"
TextBox6.Clear()
TextBox7.Clear()
TextBox4.Clear()
TextBox5.Clear()
(digunakan
apabila persamaan kuadrat yang dimasukkan tidak memiliki akar-akar dan
memunculkannya di textbox yang diinginkan (textbox8dan9))
End If
End Sub
6. Button3 (refresh) digunakan untuk menghapus
persamaan kuadrat dan akar-akarnya.
Masukkan listing sebagai berikut :
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
TextBox6.Clear()
TextBox7.Clear()
TextBox8.Clear()
TextBox9.Clear()
End Sub
7. Button2 (close) digunakan untuk keluar dari
program. Masukan listing sebagai berikut :
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button2.Click
Close()
End Sub
KOMPONEN-KOMPONEN
TOOLS
KOMPONEN
|
PROPERTIES
|
KETERANGAN
|
Form1
|
Name
text
|
|
Label1
|
Name
Text
|
Label1
x² +
|
Label2
|
Name
Text
|
Label2
x +
|
Label3
|
Name
Text
|
Label3
Program
aplikasi persamaan kuadrat
|
Label4
|
Name
Text
|
Label4
X1
|
Label5
|
Name
Text
|
Label5
X2
|
Label6
|
Name
Text
|
Label6
Akar berlainan
|
Label7
|
Name
text
|
Label7
Akar kembar
|
Label8
|
Name
Text
|
Label8
Akar tidak
real
|
Button1
|
Name
Text
|
Button1
Calculate
|
Button2
|
Name
Text
|
Button2
Close
|
Button3
|
Name
Text
|
Button3
Refresh
|
Textbox1
|
Name
Text
|
Textbox1
|
Textbox2
|
Name
Text
|
Textbox2
|
Textbox3
|
Name
Text
|
Textbox3
|
Textbox4
|
Name
Text
|
Textbox4
|
Textbox5
|
Name
Text
|
Textbox5
|
Textbox6
|
Name
Text
|
Textbox6
|
Textbox7
|
Name
Text
|
Textbox7
|
Textbox8
|
Name
Text
|
Textbox8
|
Textbox9
|
Name
Text
|
Textbox9
|
TUTORIAL BANGUN 2D & 3D
TUTORIAL BANGUN 2D & 3D
1.
Buka visual basic 2010 lau klik new
project dan pilih windows form application
2.
Form 1
·
Masukkan label dan button yang
dibutuhkan seperti gambar di bawah ini :
·
Masukkan listing pada button1 (2d) untuk
memunculkan form bangun 2d
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button1.Click
Form2.Show()
Me.Hide()
End Sub
·
Masukkan listing pada button2 (3d) untuk
memunculkan form bangu 3d
Private Sub Button2_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button2.Click
Form3.Show()
Me.Hide()
End Sub
·
Masukkan listing pada button3 (close)
untu menutup program
Private Sub Button3_Click(ByVal sender As
System.Object, ByVal
e As System.EventArgs)
Handles Button3.Click
Me.Close()
End Sub
3.
Masukkan listing berikut ini pada form2
untuk membuat bangun 2 dimensi
Public Class Form2
Dim luaspersegi As Integer
Dim sisi As Integer
Dim luaspersegipanjang As
Integer
Dim panjang As Integer
Dim lebar As Integer
(untuk mendeklarasikan ukuran dan luas)
Private Sub
RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged
GroupBox1.Visible = True
GroupBox2.Visible = False
End Sub
(untuk memunculkan groupbox1 dan menyembunyikan
groupbox2 ketika mengklik radiobutton1)
Private Sub
RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton2.CheckedChanged
GroupBox1.Visible = False
GroupBox2.Visible = True
End Sub
(untuk memunculkan groupbox2 dan menyembunyikan
groupbox1 ketika mengklik radiobutton2)
Private Sub
TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox1.TextChanged
sisi
= Val(TextBox1.Text)
End Sub
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
luaspersegi = sisi ^ 2
TextBox2.Text = luaspersegi
RectangleShape1.Visible = True
RectangleShape2.Visible = False
RectangleShape1.Width = TextBox2.Text * 2
RectangleShape1.Height = TextBox2.Text * 2
End Sub
(untuk menghitung luas persegi dan memunculkan
persegi)
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TextBox1.Clear()
TextBox2.Clear()
RectangleShape1.Hide()
End Sub
(untuk mereset data dan gambar)
Private Sub
TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox3.TextChanged
panjang = Val(TextBox3.Text)
End Sub
Private Sub
TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
TextBox4.TextChanged
lebar
= Val(TextBox4.Text)
End Sub
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
luaspersegipanjang = panjang * lebar
TextBox5.Text = luaspersegipanjang
RectangleShape1.Visible = False
RectangleShape2.Visible = True
RectangleShape2.Width = TextBox5.Text * 2
RectangleShape2.Height = TextBox5.Text * 2
End Sub
(untuk menghitung luas persegi panjang dan
memunculkan persegi panjang)
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
TextBox3.Clear()
TextBox4.Clear()
TextBox5.Clear()
RectangleShape2.Hide()
End Sub
(untuk mereset data dan gambar)
Private Sub
Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
Form1.Show()
Me.Hide()
End Sub
(untuk memunculkan form1)
End Class
4.
Masukkan listing berikut untuk membuat
bangun 3 dimensi
Public Class Form3
Private Sub
RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton1.CheckedChanged
GroupBox1.Visible = True
GroupBox2.Visible = False
End Sub
(untuk memunculkan groupbox1 dan menyembunyikn
groupbox2 ketika radiobutton1 diklik)
Private Sub
RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
RadioButton2.CheckedChanged
GroupBox1.Visible = False
GroupBox2.Visible = True
End Sub
(untuk memunculkan groupbox2 dan menyembunyikn
groupbox1 ketika radiobutton2 diklik)
Private Sub
Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If RadioButton1.Checked = True
Then
Dim myGraphics As Graphics = Panel1.CreateGraphics
Dim myPen As Pen
myPen = New Pen(Drawing.Color.Beige, 3)
Dim x1 As New Integer
Dim x2 As New Integer
Dim y1 As New Integer
Dim y2 As New Integer
Dim width As New Integer
Dim height As New Integer
Dim myRect As New Rectangle
width = TextBox1.Text
height = TextBox1.Text
myRect.Width = TextBox1.Text
myRect.Height = TextBox1.Text
myRect.X = 100
myRect.Y = (100 + width / 2)
myGraphics.DrawRectangle(myPen, myRect)
myRect.X = (100 + width / 2)
myRect.Y = 100
myGraphics.DrawRectangle(myPen, myRect)
x1 = 100
y1 = (100 + width / 2)
x2 = (100 + width / 2)
y2 = 100
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
y1 = y1 + width
y2 = y2 + width
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
x1 = x1 + width
x2 = x2 + width
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
y1 = y1 - width
y2 = y2 - width
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
End If
End Sub
(digunakan untuk menggambar bangun 3 dimensi berupa
kubus)
Private Sub
Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Panel1.Refresh()
TextBox1.Clear()
TextBox5.Clear()
End Sub
(untuk mereset data dan gambar)
Private Sub
Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
If RadioButton2.Checked = True
Then
Dim myGraphics As Graphics = Panel1.CreateGraphics
Dim myPen As Pen
myPen = New Pen(Drawing.Color.DarkGoldenrod, 3)
Dim x1 As New Integer
Dim x2 As New Integer
Dim y1 As New Integer
Dim y2 As New Integer
Dim width As New Integer
Dim height As New Integer
Dim lebar As New Integer
Dim myRect As New Rectangle
width = TextBox2.Text
height = TextBox4.Text
lebar = TextBox3.Text
myRect.Width = TextBox2.Text
myRect.Height = TextBox4.Text
myRect.X = 100
myRect.Y = (100 + lebar / 2)
myGraphics.DrawRectangle(myPen, myRect)
myRect.X = (100 + lebar / 2)
myRect.Y = 100
myGraphics.DrawRectangle(myPen, myRect)
x1 = 100
y1 = (100 + lebar / 2)
x2 = (100 + lebar / 2)
y2 = 100
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
y1 = y1 + height
y2 = y2 + height
myGraphics.DrawLine(myPen, x1, y1, x2,
y2)
x1 = x1 + width
x2 = x2 + width
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
y1 = y1 - height
y2 = y2 - height
myGraphics.DrawLine(myPen, x1, y1, x2, y2)
End If
End Sub
(digunakan untuk menggambar bangun 3 dimensi berupa
balok)
Private Sub
Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button4.Click
Panel1.Refresh()
TextBox2.Clear()
TextBox3.Clear()
TextBox4.Clear()
End Sub
(untuk mereset data dan gambar)
Private Sub
Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
Form1.Show()
Me.Hide()
End Sub
(digunakan untuk memunculkan form1)
Private Sub
Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button6.Click
Dim panjangsisi As Integer
Dim volume As Integer
panjangsisi
= Val(TextBox1.Text)
volume = panjangsisi ^ 3
TextBox5.Text = volume
End Sub
(digunakan untuk perumusan dan perhitungan volume
kubus)
Private Sub
Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button7.Click
Dim panjang As Integer
Dim lebar As Integer
Dim tinggi As Integer
Dim volume As Integer
panjang = Val(TextBox2.Text)
lebar
= Val(TextBox3.Text)
tinggi = Val(TextBox4.Text)
volume = panjang * lebar * tinggi
TextBox3.Text = volume
End Sub
(digunakan untuk perumusan dan perhitungan volume
balok)
End Class
KOMPONEN-KOMPONEN
TOOLS
KOMPONEN
|
PROPERTIES
|
KETERANGAN
|
Form1
|
Name
Text
|
Form1
|
Label1
|
Name
Text
|
Label1
Bangun 2d 3d
|
Button1
|
Name
Text
|
Button1
2d
|
Button2
|
Name
Text
|
Button2
3d
|
Button3
|
Name
Text
|
Button3
Close
|
Form2
|
Name
Text
|
Form2
|
Label1
|
Name
Text
|
Label1
Silahkan pilih
|
Label2
|
Name
Text
|
Label2
Sisi
|
Label3
|
Name
Text
|
Label3
Luas
|
Label4
|
Name
Text
|
Label4
Panjang
|
Label5
|
Name
Text
|
Label5
Lebar
|
Label6
|
Name
Text
|
Label6
Luas
|
Radiobutton1
|
Name
Text
|
Radiobutton1
Persegi
|
Radiobutton2
|
Name
Text
|
Radiobutton2
Persegi panjang
|
Textbox1
|
Name
Text
|
Textbox1
|
Textbox2
|
Name
Text
|
Textbox2
|
Textbox3
|
Name
Text
|
Textbox3
|
Textbox4
|
Name
Text
|
Textbox4
|
Textbox5
|
Name
Text
|
Textbox5
|
Groupbox1
|
Name
Text
|
Groupbox1
Persegi
|
Groupbox2
|
Name
Text
|
Groupbox2
Persegi panjang
|
Button1
|
Name
Text
|
Button1
Ok
|
Button2
|
Name
Text
|
Button2
Reset
|
Button3
|
Name
Text
|
Button3
Ok
|
Button4
|
Name
Text
|
Button4
Reset
|
Button5
|
Name
Text
|
Button5
Back
|
Rectangleshape1
|
Name
Text
|
Rectangleshape1
|
Rectangleshape2
|
Name
Text
|
Rectangleshape2
|
Panel1
|
Name
Text
|
Panel1
|
Form3
|
Name
Text
|
Form3
|
Label1
|
Name
Text
|
Label1
Silahkan pilih
|
Label2
|
Name
Text
|
Label2
Sisi
|
Label3
|
Name
Text
|
Label3
Panjang
|
Label4
|
Name
Text
|
Label4
Lebar
|
Label5
|
Name
Text
|
Label5
Tinggi
|
Label6
|
Name
Text
|
Label6
Volume
|
Label7
|
Name
text
|
Label7
Volume
|
Radiobutton1
|
Name
Text
|
Radiobutton1
Kubus
|
Radiobutton2
|
Name
Text
|
Radiobutton2
Balok
|
Textbox1
|
Name
Text
|
Textbox1
|
Textbox2
|
Name
Text
|
Textbox2
|
Textbox3
|
Name
Text
|
Textbox3
|
Textbox4
|
Name
Text
|
Textbox4
|
Textbox5
|
Name
Text
|
Textbox5
|
Textbox6
|
Name
Text
|
Textbox6
|
Button1
|
Name
Text
|
Button1
Ok
|
Button2
|
Name
Text
|
Button2
Reset
|
Button
|
Name
Text
|
Button3
Ok
|
Button
|
Name
Text
|
Button4
Reset
|
Button
|
Name
Text
|
Button5
Back
|
Button
|
Name
Text
|
Button6
Kalkulasi
|
Button
|
Name
Text
|
Button7
Kalkulasi
|
Groupbox1
|
Name
Text
|
Groupbox1
|
Groupbox2
|
Name
Text
|
Groupbox2
|
Panel1
|
Name
Text
|
Panel1
|
Langganan:
Postingan (Atom)