MEMBUAT ARRAY
DARI DATA MAHASISWA
ASSALAMU'ALAIKUM WARAHMATULLAHI WABAROKATUH :)
SELAMAT DATANG DI BLOG SAYA, SAYA AKAN MEMPOSTING
MENGENAI PROGRAM VISUAL BASIC 10 YANG
SAYA BUAT
PROJECT LATIHAN 15
BERIKUT ADALAH CODING MEMBUAT ARRAY DARI DATA MAHASISWA:
Public Class Formlat_15
Public NIM(30), Nama(30), Alamat(30), data(30),
Namafile, isifile As String
Dim n As Integer
Sub simpan_data()
n = Val(Me.lburut.Text)
NIM(n) = Me.TxtNIM.Text
Nama(n) = Me.TxtNama.Text
Alamat(n) =
Me.TxtAlamat.Text
'menyimpan data
data(n) = "NIM : " & NIM(n) & " "
& _
"Nama:" & Nama(n) & " "
& _
"Alamat:" & Alamat(n)
'menyimpan data
PrintLine(1, data(n))
'Print(1, NIM(n), Nama(n), Alamat(n), Chr(13))
'PrintLine(1, NIM(n), Nama(n), Alamat(n)
n += 1
Me.lburut.Text = n.ToString
End Sub
Sub cari_data()
Dim NIMcari As String
Dim i As Integer
Dim ditemukan As Boolean
'yang dicari berdasarkan NIM
NIMcari =
InputBox("Masukan NIM yang akan di cari
:")
'proses pencarian dan menampilkan hasil
For i = 0 To n - 1
If NIMcari = NIM(i) Then
Me.TxtNIM.Text = NIM(i).ToString
Me.TxtNama.Text = Nama(i).ToString
Me.TxtAlamat.Text = Alamat(i).ToString
ditemukan = True
Exit For
Else
ditemukan = False
End If
Next
If ditemukan = False Then
MsgBox("Data tidak di temukan !", vbCritical, "Informasi.")
End If
End Sub
Sub cetak_data()
Me.Rtxdata.Clear()
Namafile = Application.StartupPath & "\mhs.txt"
FileOpen(1,
Namafile, OpenMode.Input)
While Not EOF(1)
Input(1, isifile)
Me.Rtxdata.AppendText(isifile & Chr(13))
End While
End Sub
Sub baru()
Me.TxtNIM.Clear()
Me.TxtNama.Clear()
Me.TxtAlamat.Clear()
Me.TxtNIM.Focus()
End Sub
Private Sub
Formlat_15_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
utama.Enabled = True
utama.Show()
Me.Hide()
FileClose(1) 'tutup file
End Sub
Private Sub
Formlat_15_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
utama.Enabled = True
utama.Show()
Me.Hide()
FileClose(1) 'tutup file
End Sub
Private Sub
BSimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
BSimpan.Click
Call simpan_data()
Call baru()
End Sub
Private Sub Bcari_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Bcari.Click
Call cari_data()
End Sub
Private Sub
Bcetak_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles
Bcetak.Click
If Me.Bcetak.Text = "&Cetak" Then
'Me.Enabled = False
'Formlat_15cetak.Show()
FileClose(1)
Me.Rtxdata.Visible = True
Call cetak_data()
Me.Bcetak.Text = "&Tutup"
ElseIf Me.Bcetak.Text
= "&Tutup" Then
Me.Rtxdata.Visible = False
Me.Bcetak.Text = "&Cetak"
FileClose(1)
Namafile = Application.StartupPath
& "\mhs.txt"
FileOpen(1, Namafile, OpenMode.Append)
End If
End Sub
Private Sub Formlat_15_Load(ByVal
sender As Object,
ByVal e As
System.EventArgs) Handles
Me.Load
'buka file untuk menyisipkan data
Namafile = Application.StartupPath & "\mhs.txt"
FileOpen(1,
Namafile, OpenMode.Output)
Me.Rtxdata.Visible = False
End Sub
End Class
DISINI SAYA MENGGUNAKAN DUA FORM UNTUK SALING BERHUBUNGAN:
FORM LATIHAN 15 CETAK :
BERIKUT CODING LATIHAN 15 CETAK:
Public Class Formlat_15cetak
Private Sub
Formlat_15cetak_FormClosed(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
Formlat_15.Enabled = True
Formlat_15.Show()
Me.Hide()
End Sub
Private Sub
Formlat_15cetak_FormClosing(ByVal sender As Object, ByVal e As
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
Formlat_15.Enabled
= True
Formlat_15.Show()
Me.Hide()
End Sub
Private Sub
Formlat_15cetak_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim i, n As Integer
Dim data(30) As String
n =
Val(Formlat_15.lburut.Text)
For i = 0 To n - 1
data(i)
= "NIM : " & Formlat_15.NIM(i) & Chr(13) & _
"Nama:" & Formlat_15.Nama(i)
& Chr(13) & _
"Alamat:" & Formlat_15.Alamat(i)
& Chr(13)
Me.Rtbcetak.AppendText(data(i))
Next
End Sub
End Class
bagaimana cara menggabungkannya...???
BalasHapus