You are on page 1of 3

Imports System Imports System.IO Imports System.

Collections

Public Class Form1 Private Sub DataReceived( _ ByVal sender As Object, _ ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) _ Handles SerialPort1.DataReceived Me.BeginInvoke(New StrDelegate(AddressOf Update1), SerialPort1.ReadLine) End Sub Public Delegate Sub StrDelegate(ByVal Data As String) Public Sub Update1(ByVal Data As String) Dim objReader As New StreamReader("c:\Database.txt") Dim sLine As String = "" Dim file As String = "" Dim len As Integer Dim flag As Integer = 0 Dim ThisMoment As Date ThisMoment = Now Do sLine = objReader.ReadLine() If Not sLine Is Nothing Then If InStr(1, sLine, Data.Substring(0, 2)) Then len = sLine.Length Label4.Text = sLine.Substring(0, 2) Label3.Text = sLine.Substring(2, len - 2) Label6.Text = ThisMoment My.Computer.FileSystem.WriteAllText("C:\Attendance.txt", sLi ne & " " & ThisMoment & vbCrLf, True) flag = 1 End If End If Loop Until sLine Is Nothing If flag = 0 Then MsgBox("User No. " & Data & " is not added") End If objReader.Close() End Sub Private Sub SendBtn_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles SendBtn.Click SerialPort1.PortName = "COM1"

SerialPort1.BaudRate SerialPort1.Parity = SerialPort1.DataBits SerialPort1.StopBits

= 57600 IO.Ports.Parity.None = 8 = IO.Ports.StopBits.One

SerialPort1.Open() Stopbtn.Enabled = True SendBtn.Enabled = False End Sub Private Sub Stopbtn_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Stopbtn.Click If SerialPort1.IsOpen Then SerialPort1.Close() Stopbtn.Enabled = False SendBtn.Enabled = True End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button1.Click If TextBox1.Text = "" Then MsgBox("Please Enter User Code") Exit Sub End If If TextBox2.Text = "" Then MsgBox("Please Enter User Full Name") Exit Sub End If My.Computer.FileSystem.WriteAllText("C:\Database.txt", TextBox1.Text & " " & TextBox2.Text & vbCrLf, True) MsgBox("Entry Added") End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.E ventArgs) Handles Button2.Click Dim objReader As New StreamReader("c:\Database.txt") Dim sLine As String = "" Dim file As String = "" Dim flag As Integer = 0 If TextBox1.Text = "" Then MsgBox("Please Enter User Code") Exit Sub End If Do sLine = objReader.ReadLine() If Not sLine Is Nothing Then If InStr(1, sLine, TextBox1.Text) Then flag = 1 Else file = file & sLine & vbCrLf End If End If

Loop Until sLine Is Nothing objReader.Close() If flag = 1 Then My.Computer.FileSystem.WriteAllText("C:\Database.txt", file, False) MsgBox("Entry Deleted") Else MsgBox("No Entry Found") End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even tArgs) Handles MyBase.Load Stopbtn.Enabled = False End Sub End Class

You might also like