Text Kayıt Örneği
‘Bunun için ilk önce c:\kayit.txt dosyası oluşturun (isterseniz ‘başka isimdede oluşturabilirsiniz). Form1 ve Form2 oluşturun.
‘Form1 e 5 adet Label, 5 adet TextBox, 4 adet Button ‘Form2 ye 1 adet TextBox, 1 adet Button koyun...
‘aşağıdaki kodları yazın...Bahadirsa
Form a yazılacak kodlar:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Text = "Kayıt İşlemleri Falan Filan vs."
Me.MaximizeBox = False
Me.Left = 250
Me.Top = 130
Me.Width = 300
Me.Height = 300
Button1.Text = "Kaydet"
Button1.Size = New System.Drawing.Size(100, 30)
Button2.Text = "Kayıt Bul"
Button2.Size = New System.Drawing.Size(100, 30)
Button3.Text = "Temizle"
Button3.Size = New System.Drawing.Size(100, 30)
Button4.Text = "Çıkış"
Button4.Size = New System.Drawing.Size(100, 30)
Label1.Text = "Kayıt No"
Label2.Text = "Adı"
Label3.Text = "Soyadı"
Label4.Text = "Mesleği"
Label5.Text = "Adresi"
End Sub
Structure personelbilgi
Public ady As String
Public soyady As String
Public mesle?i As String
Public adresi As String
Public string2 As String
End Structure
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Kayıt Numarası Gir")
Exit Sub
End If
Dim personel As personelbilgi
personel.adı = TextBox2.Text
personel.soyadı = TextBox3.Text
personel.mesleği = TextBox4.Text
personel.adresi = TextBox5.Text
personel.string2 = "Kayıt Örnek"
FileOpen(1, "C:\kayit.txt", OpenMode.Random, OpenAccess.ReadWrite)
FilePut(1, personel, CInt(TextBox1.Text))
FileClose(1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Form2.TextBox1.Text = ""
Form2.Show()
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 8 Then
e.Handled = False
Exit Sub
End If
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
MessageBox.Show("Sadece Sayı Girebilirsiniz.Bahadirsa...", "Dikkat!!", MessageBoxButtons.OK)
Exit Sub
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Close()
End Sub
End Class
Form2 e yazılacak kodlar:
Public Class Form2
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = "" Then
MsgBox("Lütfen Sayı Giriniz...Bahadirsa")
Exit Sub
End If
Dim personel As Form1.personelbilgi
FileOpen(1, "C:\kayit.txt", OpenMode.Random, OpenAccess.ReadWrite)
FileGet(1, personel, CInt(TextBox1.Text))
FileClose(1)
Form1.TextBox1.Text = TextBox1.Text
Form1.TextBox2.Text = personel.adı
Form1.TextBox3.Text = personel.soyadı
Form1.TextBox4.Text = personel.mesleği
Form1.TextBox5.Text = personel.adresi
Form1.Show()
Me.Hide()
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Text = "Kayıt No‘ya Göre Kayıt Bul"
Me.Left = 470
Me.Top = 145
Me.Width = 270
Me.Height = 109
Button1.Size = New System.Drawing.Size(140, 30)
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.SizableToolWindow
End Sub
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) = 8 Then
e.Handled = False
Exit Sub
End If
If Asc(e.KeyChar) < 48 Or Asc(e.KeyChar) > 57 Then
e.Handled = True
MessageBox.Show("Sadece Sayı Girebilirsiniz.Bahadirsa...", "Dikkat!!", MessageBoxButtons.OK)
Exit Sub
End If
End Sub
End Class