Program Invers Matriks 3x3 dengan VB 6
Kali ini saya akan memebuat program mencari invers matriks 3x3 dengan program VB 6
Private Sub cmdBackToProgram_Click()
Unload Me
frmMain.cmdValue.SetFocus
End Sub
Private Sub Form_Load()
Me.txtV1.Text = frmMain.txtR1.Text
Me.txtV2.Text = frmMain.txtR2.Text
Me.txtV3.Text = frmMain.txtR3.Text
Me.txtV4.Text = frmMain.txtR4.Text
Me.txtV5.Text = frmMain.txtR5.Text
Me.txtV6.Text = frmMain.txtR6.Text
Me.txtV7.Text = frmMain.txtR7.Text
Me.txtV8.Text = frmMain.txtR8.Text
Me.txtV9.Text = frmMain.txtR9.Text
Me.txtV1.Text = FormatNumber(txtV1.Text, 3)
Me.txtV2.Text = FormatNumber(txtV2.Text, 3)
Me.txtV3.Text = FormatNumber(txtV3.Text, 3)
Me.txtV4.Text = FormatNumber(txtV4.Text, 3)
Me.txtV5.Text = FormatNumber(txtV5.Text, 3)
Me.txtV6.Text = FormatNumber(txtV6.Text, 3)
Me.txtV7.Text = FormatNumber(txtV7.Text, 3)
Me.txtV8.Text = FormatNumber(txtV8.Text, 3)
Me.txtV9.Text = FormatNumber(txtV9.Text, 3)
End Sub
Tampilan awal program
Masukan angka pada form Matriks A
Jika yang keluar determinannya adalah 0 maka akan keluar peringatan sebagai berikut
Jika determinan tidak bernilai 0 maka hasilnya akan seperti ini
Untuk melihat lebih detail maka dapat diklik pada tombol nilai penuh
Program :
Main Form
Private Sub cmdCleaning_Click()
txtA1.Text = ""
txtA2.Text = ""
txtA3.Text = ""
txtA4.Text = ""
txtA5.Text = ""
txtA6.Text = ""
txtA7.Text = ""
txtA8.Text = ""
txtA9.Text = ""
txtR1.Text = ""
txtR2.Text = ""
txtR3.Text = ""
txtR4.Text = ""
txtR5.Text = ""
txtR6.Text = ""
txtR7.Text = ""
txtR8.Text = ""
txtR9.Text = ""
txtDeterminant.Text = ""
txtB1.Text = ""
txtB2.Text = ""
txtB3.Text = ""
txtB4.Text = ""
txtB5.Text = ""
txtB6.Text = ""
txtB7.Text = ""
txtB8.Text = ""
txtB9.Text = ""
End Sub
Private Sub cmdExit_Click()
Call Form_Unload(Cancel = 0)
End Sub
Private Sub cmdProcess_Click()
On Error GoTo Err
Me.txtB1.Text = (-1 * -1) * ((Val(Me.txtA5.Text) * Val(Me.txtA9.Text)) - (Val(Me.txtA6.Text) * Val(Me.txtA8.Text)))
Me.txtB4.Text = (-1 * -1 * -1) * ((Val(Me.txtA4.Text) * Val(Me.txtA9.Text)) - (Val(Me.txtA6.Text) * Val(Me.txtA7.Text)))
Me.txtB7.Text = (-1 * -1 * -1 * -1) * ((Val(Me.txtA4.Text) * Val(Me.txtA8.Text)) - (Val(Me.txtA5.Text) * Val(Me.txtA7.Text)))
Me.txtB2.Text = (-1 * -1 * -1) * ((Val(Me.txtA2.Text) * Val(Me.txtA9.Text)) - (Val(Me.txtA3.Text) * Val(Me.txtA8.Text)))
Me.txtB5.Text = (-1 * -1 * -1 * -1) * ((Val(Me.txtA1.Text) * Val(Me.txtA9.Text)) - (Val(Me.txtA3.Text) * Val(Me.txtA7.Text)))
Me.txtB8.Text = (-1 * -1 * -1 * -1 * -1) * ((Val(Me.txtA1.Text) * Val(Me.txtA8.Text)) - (Val(Me.txtA2.Text) * Val(Me.txtA7.Text)))
Me.txtB3.Text = (-1 * -1 * -1 * -1) * ((Val(Me.txtA2.Text) * Val(Me.txtA6.Text)) - (Val(Me.txtA3.Text) * Val(Me.txtA5.Text)))
Me.txtB6.Text = (-1 * -1 * -1 * -1 * -1) * ((Val(Me.txtA1.Text) * Val(Me.txtA6.Text)) - (Val(Me.txtA3.Text) * Val(Me.txtA4.Text)))
Me.txtB9.Text = (-1 * -1 * -1 * -1 * -1 * -1) * ((Val(Me.txtA1.Text) * Val(Me.txtA5.Text)) - (Val(Me.txtA2.Text) * Val(Me.txtA4.Text)))
p1 = (Val(Me.txtA1.Text) * Val(Me.txtA5.Text) * Val(Me.txtA9.Text))
p2 = (Val(Me.txtA2.Text) * Val(Me.txtA6.Text) * Val(Me.txtA7.Text))
p3 = (Val(Me.txtA3.Text) * Val(Me.txtA4.Text) * Val(Me.txtA8.Text))
q1 = (Val(Me.txtA2.Text) * Val(Me.txtA4.Text) * Val(Me.txtA9.Text))
q2 = (Val(Me.txtA1.Text) * Val(Me.txtA6.Text) * Val(Me.txtA8.Text))
q3 = (Val(Me.txtA3.Text) * Val(Me.txtA5.Text) * Val(Me.txtA7.Text))
Me.txtDeterminant.Text = (p1 + p2 + p3) - (q1 + q2 + q3)
Me.txtR1.Text = Val(Me.txtB1.Text) / Val(Me.txtDeterminant)
Me.txtR2.Text = Val(Me.txtB2.Text) / Val(Me.txtDeterminant)
Me.txtR3.Text = Val(Me.txtB3.Text) / Val(Me.txtDeterminant)
Me.txtR4.Text = Val(Me.txtB4.Text) / Val(Me.txtDeterminant)
Me.txtR5.Text = Val(Me.txtB5.Text) / Val(Me.txtDeterminant)
Me.txtR6.Text = Val(Me.txtB6.Text) / Val(Me.txtDeterminant)
Me.txtR7.Text = Val(Me.txtB7.Text) / Val(Me.txtDeterminant)
Me.txtR8.Text = Val(Me.txtB8.Text) / Val(Me.txtDeterminant)
Me.txtR9.Text = Val(Me.txtB9.Text) / Val(Me.txtDeterminant)
Me.txtR1.Text = FormatNumber(txtR1.Text, 3)
Me.txtR2.Text = FormatNumber(txtR2.Text, 3)
Me.txtR3.Text = FormatNumber(txtR3.Text, 3)
Me.txtR4.Text = FormatNumber(txtR4.Text, 3)
Me.txtR5.Text = FormatNumber(txtR5.Text, 3)
Me.txtR6.Text = FormatNumber(txtR6.Text, 3)
Me.txtR7.Text = FormatNumber(txtR7.Text, 3)
Me.txtR8.Text = FormatNumber(txtR8.Text, 3)
Me.txtR9.Text = FormatNumber(txtR9.Text, 3)
cmdValue.Visible = True
cmdValue.SetFocus
Exit Sub
Err: Call Error
End Sub
Private Sub cmdValue_Click()
frmValue.Show vbModal
End Sub
Private Sub Form_Activate()
txtA1.Text = ""
txtA2.Text = ""
txtA3.Text = ""
txtA4.Text = ""
txtA5.Text = ""
txtA6.Text = ""
txtA7.Text = ""
txtA8.Text = ""
txtA9.Text = ""
txtR1.Text = ""
txtR2.Text = ""
txtR3.Text = ""
txtR4.Text = ""
txtR5.Text = ""
txtR6.Text = ""
txtR7.Text = ""
txtR8.Text = ""
txtR9.Text = ""
txtDeterminant.Text = ""
txtB1.Text = ""
txtB2.Text = ""
txtB3.Text = ""
txtB4.Text = ""
txtB5.Text = ""
txtB6.Text = ""
txtB7.Text = ""
txtB8.Text = ""
txtB9.Text = ""
End Sub
Private Sub Form_Unload(Cancel As Integer)
Warning = MsgBox("Anda yakin ingin keluar dari program?", vbQuestion + vbYesNo, "Konfirmasi")
If Warning = vbYes Then
End
Else
If cmdValue.Visible = True Then
Cancel = 1
cmdValue.SetFocus
Else
Cancel = 1
Me.txtA1.SetFocus
End If
End If
End Sub
Sub EmptyMatrixB()
Me.txtB1.Text = ""
Me.txtB2.Text = ""
Me.txtB3.Text = ""
Me.txtB4.Text = ""
Me.txtB5.Text = ""
Me.txtB6.Text = ""
Me.txtB7.Text = ""
Me.txtB8.Text = ""
Me.txtB9.Text = ""
End Sub
Sub EmptyResult()
Me.txtR1.Text = ""
Me.txtR2.Text = ""
Me.txtR3.Text = ""
Me.txtR4.Text = ""
Me.txtR5.Text = ""
Me.txtR6.Text = ""
Me.txtR7.Text = ""
Me.txtR8.Text = ""
Me.txtR9.Text = ""
End Sub
Sub Error()
If Me.txtA1.Text = "" Then
ElseIf Me.txtA2.Text = "" Then
ElseIf Me.txtA3.Text = "" Then
ElseIf Me.txtA4.Text = "" Then
ElseIf Me.txtA5.Text = "" Then
ElseIf Me.txtA6.Text = "" Then
ElseIf Me.txtA7.Text = "" Then
ElseIf Me.txtA8.Text = "" Then
ElseIf Me.txtA9.Text = "" Then
End If
If Me.txtDeterminant.Text = 0 Then
If Me.txtB1.Text = 0 Then
Me.txtR1.Text = "-Inf"
ElseIf Me.txtB1.Text >= 0 Then
Me.txtR1.Text = "Inf"
End If
If Me.txtB2.Text = 0 Then
Me.txtR2.Text = "-Inf"
ElseIf Me.txtB2.Text >= 0 Then
Me.txtR2.Text = "Inf"
End If
If Me.txtB3.Text = 0 Then
Me.txtR3.Text = "-Inf"
ElseIf Me.txtB3.Text >= 0 Then
Me.txtR3.Text = "Inf"
End If
If Me.txtB4.Text = 0 Then
Me.txtR4.Text = "-Inf"
ElseIf Me.txtB4.Text >= 0 Then
Me.txtR4.Text = "Inf"
End If
If Me.txtB5.Text = 0 Then
Me.txtR5.Text = "-Inf"
ElseIf Me.txtB5.Text >= 0 Then
Me.txtR5.Text = "Inf"
End If
If Me.txtB6.Text = 0 Then
Me.txtR6.Text = "-Inf"
ElseIf Me.txtB6.Text >= 0 Then
Me.txtR6.Text = "Inf"
End If
If Me.txtB7.Text = 0 Then
Me.txtR7.Text = "-Inf"
ElseIf Me.txtB7.Text >= 0 Then
Me.txtR7.Text = "Inf"
End If
If Me.txtB8.Text = 0 Then
Me.txtR8.Text = "-Inf"
ElseIf Me.txtB8.Text >= 0 Then
Me.txtR8.Text = "Inf"
End If
If Me.txtB9.Text < 0 Then
Me.txtR9.Text = "-Inf"
ElseIf Me.txtB9.Text >= 0 Then
Me.txtR9.Text = "Inf"
End If
MsgBox "Nilai yang anda input tidak sesuai karena bernilai Determinan = " + txtDeterminant.Text, vbCritical + vbOKOnly, "Kesalahan!"
End If
End Sub
Sub lblDefault()
lblMatrixB.Caption = "Matriks B"
lblResult.Caption = "Hasil"
End Sub
Value form
Unload Me
frmMain.cmdValue.SetFocus
End Sub
Private Sub Form_Load()
Me.txtV1.Text = frmMain.txtR1.Text
Me.txtV2.Text = frmMain.txtR2.Text
Me.txtV3.Text = frmMain.txtR3.Text
Me.txtV4.Text = frmMain.txtR4.Text
Me.txtV5.Text = frmMain.txtR5.Text
Me.txtV6.Text = frmMain.txtR6.Text
Me.txtV7.Text = frmMain.txtR7.Text
Me.txtV8.Text = frmMain.txtR8.Text
Me.txtV9.Text = frmMain.txtR9.Text
Me.txtV1.Text = FormatNumber(txtV1.Text, 3)
Me.txtV2.Text = FormatNumber(txtV2.Text, 3)
Me.txtV3.Text = FormatNumber(txtV3.Text, 3)
Me.txtV4.Text = FormatNumber(txtV4.Text, 3)
Me.txtV5.Text = FormatNumber(txtV5.Text, 3)
Me.txtV6.Text = FormatNumber(txtV6.Text, 3)
Me.txtV7.Text = FormatNumber(txtV7.Text, 3)
Me.txtV8.Text = FormatNumber(txtV8.Text, 3)
Me.txtV9.Text = FormatNumber(txtV9.Text, 3)
End Sub




Komentar
Posting Komentar