Using strings in a .INI or .TXT file

Do you need something made? then ask in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
26 posts Page 3 of 3
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello Diazepa,

Yes but I mean how does a person logout?. So far the code we have been doing tells us when the user has logged in and takes a picture of them and stuff like that. How is a person going to logout?, will they have to enter the ID number again as they leave?.

Thank you.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

Precicely :)
Same action as logging in, but only difference is that the log tells that the person logged out:)
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello Diazepa,

A quick cheap way of doing this would be to create a file with the users ID when they first login. The code below is the "TextBox1_TextChanged" event code that ive changed. It includes the webcam image saver and email code aswell so you may need to go through it and make a couple of small changes.

The new code:
Code: Select all
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        Dim data As IDataObject
        Dim bmap As Image
        If TextBox1.Text.Length = "4" Then
            GetUsersName = ""
            Dim lines() As String = File.ReadAllLines("C:\Konf Reg\Konf Medlemmer.ini")
            Dim IDfinder As String = TextBox1.Text
            For Each line As String In lines
                If line.IndexOf(IDfinder) <> -1 Then
                    FindIDOfUser = line
                    GetUsersName = FindIDOfUser.Split("="c)(0)
                    '/////////////// NEW CODE /////////////////
                    If My.Computer.FileSystem.FileExists("C:\" + FindIDOfUser.Split("="c)(1) + ".lio") Then
                        Form3.TextBox1.Text = TextBox1.Text + vbNewLine + GetUsersName + " Logged Out at: " + Label1.Text + "!"
                        My.Computer.FileSystem.DeleteFile("C:\" + FindIDOfUser.Split("="c)(1) + ".lio", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                    Else
                        My.Computer.FileSystem.WriteAllText("C:\" + FindIDOfUser.Split("="c)(1) + ".lio", "Logged In", False)
                        '/////////////////END NEW CODE//////////
                        SendMessage(hWnd, WM_CAP_EDIT_COPY, 640, 480)
                        data = Clipboard.GetDataObject()
                        If data.GetDataPresent(GetType(System.Drawing.Bitmap)) Then
                            bmap = CType(data.GetData(GetType(System.Drawing.Bitmap)), Image)
                            PictureBox1.Image = bmap
                            bmap.Save("C:\" + GetUsersName + ".jpg", Imaging.ImageFormat.Jpeg)
                        End If
                        Form3.TextBox1.Text = TextBox1.Text + vbNewLine + GetUsersName + " Logged In at: " + Label1.Text + "!"
                        Dim from As New MailAddress("Youremail@address.com") 'Change
                        Dim [to] As New MailAddress("Youremail@address.com") 'Change
                        Dim theMailMessage As New MailMessage(from, [to])
                        theMailMessage.Body = GetUsersName + "Has just logged in!"
                        theMailMessage.Attachments.Add(New Attachment("C:\" + GetUsersName + ".jpg"))
                        theMailMessage.Subject = "New logged in"
                         Dim theClient As New SmtpClient("youremail.server.com) ' Change
                        theClient.UseDefaultCredentials = False
                        Dim theCredential As New System.Net.NetworkCredential("USERNAME", "PASSWORD") 'Change
                        theClient.Credentials = theCredential
                        theClient.EnableSsl = True
                        Try
                            theClient.Send(theMailMessage)
                        Catch wex As Net.WebException
                            MessageBox.Show("Could not send email...check your settings.")
                        End Try
                        MsgBox("E-mail successfully sent !")

                    End If
                End If
            Next
            If GetUsersName = "" Then
                MsgBox("Unregistered", MsgBoxStyle.Critical, "Ops! Uregistrert nummer!")
            End If
        End If
    End Sub
In this code all I added was this:
Code: Select all
If My.Computer.FileSystem.FileExists("C:\" + FindIDOfUser.Split("="c)(1) + ".lio") Then
                        Form3.TextBox1.Text = TextBox1.Text + vbNewLine + GetUsersName + " Logged Out at: " + Label1.Text + "!"
                        My.Computer.FileSystem.DeleteFile("C:\" + FindIDOfUser.Split("="c)(1) + ".lio", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
                    Else
                        My.Computer.FileSystem.WriteAllText("C:\" + FindIDOfUser.Split("="c)(1) + ".lio", "Logged In", False)
What this code does is when a user entered there ID into the system it will check if they are logging in or logging out. If they are logging in it will take a photo and send it via email as normal and save "User has logged in" to the log file. It will also create a file using there userID and save it onto the system. The when the user enters there userID again (to say they are logging out) it will check to see if a file exists on the system with there userID number and if it does then it will erase the file and save "User has logged out" to the log and skip the image taking and email part. If that makes sense?

Its a cheap way of doing it but effective all the same.

Hope that helps cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

Uhm :P Not to be picky, but the cam wont choose open itself - it just focuses/mark it in the listbox :P

Great work :D
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Oh yes change your "ListBox1_SelectedIndexChanged" event to this:
Code: Select all
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        CamSource = ListBox1.SelectedIndex
        previewCamera(PictureBox1)
      End Sub
That should do it cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

Thanks :D it has a few errors but, ill sort those out myself :D
Thanks ^^,
26 posts Page 3 of 3
Return to “Tutorial Requests”