Nesneler
5 TextBox
1 Datagridviev
5 Buton
5 Label
Form Kodları
Modül Kodları
5 TextBox
1 Datagridviev
5 Buton
5 Label
Form Kodları
Public Class Form1
Dim dn As Byte
Dim x As Integer
Dim ogr As ogrenci
Dim veri(4) As String
Dim sayac As Integer = 1
Dim pos As Integer
Dim cevap As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'ögrenci kayıt
dn = FreeFile()
x = sonkayıt()
ogr.isaret = "*"
ogr.no = Short.Parse(TextBox1.Text)
ogr.ad = TextBox2.Text
ogr.soyad = TextBox3.Text
ogr.not1 = CByte(TextBox4.Text)
ogr.not2 = CByte(TextBox5.Text)
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(ogr))
FilePut(dn, ogr, x)
FileClose(dn)
yenile()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
'tüm kayıtlar
dn = FreeFile()
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(ogr))
DataGridView1.Rows.Clear()
Do While Not EOF(dn)
FileGet(dn, ogr, sayac)
If ogr.isaret = "*" Then
veri(0) = ogr.no
veri(1) = ogr.ad
veri(2) = ogr.soyad
veri(3) = ogr.not1
veri(4) = ogr.not2
DataGridView1.Rows.Add(veri)
End If
sayac = sayac + 1
Loop
FileClose(dn)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
'ögrenci bul
dn = FreeFile()
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(ogr))
Do While Not EOF(dn)
FileGet(dn, ogr, )
If ogr.no = Short.Parse(TextBox1.Text) And ogr.isaret = "*" Then
pos = Loc(dn)
TextBox2.Text = ogr.ad
TextBox3.Text = ogr.soyad
TextBox4.Text = ogr.not1
TextBox5.Text = ogr.not2
Exit Do
End If
Loop
If pos = 0 Then MsgBox("Aradıgınız Kişi Bulunamadı")
FileClose()
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
'sil
dn = FreeFile()
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(ogr))
cevap = MsgBox("Bu kayıtı silmek istediğinizden emin misiniz?", MsgBoxStyle.Critical + MsgBoxStyle.YesNo, "dikkat")
If cevap = vbYes Then
Seek(dn, pos)
ogr.isaret = "-"
ogr.no = Short.Parse(TextBox1.Text)
ogr.ad = TextBox2.Text
ogr.soyad = TextBox3.Text
ogr.not1 = CByte(TextBox4.Text)
ogr.not2 = CByte(TextBox5.Text)
FilePut(dn, ogr)
End If
FileClose(dn)
yenile()
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
'değiştir
dn = FreeFile()
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(ogr))
cevap = MsgBox("Bu kayıtı degiştirmek istediğinizden emin misiniz?", MsgBoxStyle.Critical + MsgBoxStyle.YesNo, "dikkat")
If cevap = vbYes Then
Seek(dn, pos)
ogr.isaret = "*"
ogr.no = Short.Parse(TextBox1.Text)
ogr.ad = TextBox2.Text
ogr.soyad = TextBox3.Text
ogr.not1 = CByte(TextBox4.Text)
ogr.not2 = CByte(TextBox5.Text)
FilePut(dn, ogr)
End If
FileClose(dn)
End Sub
Sub yenile()
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Modül Kodları
Module Module1
Structure ogrenci
Dim isaret As Char
Dim no As Short
<VBFixedString(15)> Dim ad As String
<VBFixedString(15)> Dim soyad As String
Dim not1 As Byte
Dim not2 As Byte
End Structure
Public Function sonkayıt()
Dim tmp As ogrenci
Dim dn As Byte
dn = FreeFile()
FileOpen(dn, "D:\veriler1.dat", OpenMode.Random, , , Len(tmp))
sonkayıt = 1
Do While Not EOF(dn)
FileGet(dn, tmp)
sonkayıt = sonkayıt + 1
Loop
FileClose()
Return sonkayıt
End Function
End Module