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 2 of 3
Contributors
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Well I dont realy know how your project is setup but if it was me making it I would probably layout the code like this:

You will need to add a ListBox and Picturebox though:
Code: Select all
Imports System
Imports System.IO
Imports System.Runtime.InteropServices
Imports Microsoft.Win32
Public Class Form1
   
    Inherits System.Windows.Forms.Form
    Const WM_CAP_START = &H400S
    Const WS_CHILD = &H40000000
    Const WS_VISIBLE = &H10000000
    Const WM_CAP_DRIVER_CONNECT = WM_CAP_START + 10
    Const WM_CAP_DRIVER_DISCONNECT = WM_CAP_START + 11
    Const WM_CAP_EDIT_COPY = WM_CAP_START + 30
    Const WM_CAP_SEQUENCE = WM_CAP_START + 62
    Const WM_CAP_FILE_SAVEAS = WM_CAP_START + 23
    Const WM_CAP_SET_SCALE = WM_CAP_START + 53
    Const WM_CAP_SET_PREVIEWRATE = WM_CAP_START + 52
    Const WM_CAP_SET_PREVIEW = WM_CAP_START + 50
    Const SWP_NOMOVE = &H2S
    Const SWP_NOSIZE = 1
    Const SWP_NOZORDER = &H4S
    Const HWND_BOTTOM = 1
    '--The capGetDriverDescription function retrieves the version 
    ' description of the capture driver--
    Declare Function capGetDriverDescriptionA Lib "avicap32.dll" _
       (ByVal wDriverIndex As Short, _
        ByVal lpszName As String, ByVal cbName As Integer, _
        ByVal lpszVer As String, _
        ByVal cbVer As Integer) As Boolean

    '--The capCreateCaptureWindow function creates a capture window--
    Declare Function capCreateCaptureWindowA Lib "avicap32.dll" _
       (ByVal lpszWindowName As String, ByVal dwStyle As Integer, _
        ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, _
        ByVal nHeight As Short, ByVal hWnd As Integer, _
        ByVal nID As Integer) As Integer

    '--This function sends the specified message to a window or windows--
    Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hwnd As Integer, ByVal Msg As Integer, _
        ByVal wParam As Integer, _
       <MarshalAs(UnmanagedType.AsAny)> ByVal lParam As Object) As Integer

    '--Sets the position of the window relative to the screen buffer--
    Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" _
       (ByVal hwnd As Integer, _
        ByVal hWndInsertAfter As Integer, ByVal x As Integer, _
        ByVal y As Integer, _
        ByVal cx As Integer, ByVal cy As Integer, _
        ByVal wFlags As Integer) As Integer

    '--This function destroys the specified window--
    Declare Function DestroyWindow Lib "user32" _
       (ByVal hndw As Integer) As Boolean

    '---used to identify the video source---
    Dim CamSource As Integer
    '---used as a window handle---
    Dim hWnd As Integer
    Public FindIDOfUser As String
    Public GetUsersName As String
    Private Sub cameraSource()
        Dim DriverName As String = Space(80)
        Dim DriverVersion As String = Space(80)
        For i As Integer = 0 To 9
            If capGetDriverDescriptionA(i, DriverName, 80, _
               DriverVersion, 80) Then
                ListBox1.Items.Add(DriverName.Trim)
            End If
        Next
    End Sub
    Private Sub previewCamera(ByVal pbCtrl As PictureBox)
        hWnd = capCreateCaptureWindowA(CamSource, _
            WS_VISIBLE Or WS_CHILD, 0, 0, 0, _
            0, pbCtrl.Handle.ToInt32, 0)
        If SendMessage( _
           hWnd, WM_CAP_DRIVER_CONNECT, _
           CamSource, 0) Then
            '---set the preview scale---
            SendMessage(hWnd, WM_CAP_SET_SCALE, True, 0)
            '---set the preview rate (ms)---
            SendMessage(hWnd, WM_CAP_SET_PREVIEWRATE, 30, 0)
            '---start previewing the image---
            SendMessage(hWnd, WM_CAP_SET_PREVIEW, True, 0)
            '---resize window to fit in PictureBox control---
            SetWindowPos(hWnd, HWND_BOTTOM, 0, 0, _
               pbCtrl.Width, pbCtrl.Height, _
               SWP_NOMOVE Or SWP_NOZORDER)
        Else
            '--error connecting to video source---
            DestroyWindow(hWnd)
        End If
    End Sub
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        CamSource = ListBox1.SelectedIndex
    End Sub
    Private Sub ListBox1_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.DoubleClick
        previewCamera(PictureBox1)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Form2.Show()
    End Sub
    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)
                    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 + " logget seg inn/ut klokken " + Label1.Text + "!"
                End If
            Next
            If GetUsersName = "" Then
                MsgBox("Unregistered", MsgBoxStyle.Critical, "Ops! Uregistrert nummer!")
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        cameraSource()
        Label3.Text = Format(Date.Now, "G")
    End Sub
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label3.Text = Format(Date.Now)
    End Sub
End Class

That code lets you select a webcam from the Listbox then when a user enters a correct ID code it will take a picture of them and save the picture as there username automatically.

Hope that helps.
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 Ill check if it works l8ter
our internet screwed me over last night :[
:ugeek:
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

How do i make the program remember a Webcamera? :)
Thanks :D
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Diazepa wrote:
How do i make the program remember a Webcamera? :)
Thanks :D
Hello Diazepa,

For some reason I wasnt informed of your reply ive just noticed it, sorry about that. As for remembering the webcam do you want to auto-start a particular webcam?. If you do then you first need to run your application and find out which ListBox slot your webcam is in, for example your listbox list may look like this:

Webcam Computer 1 (Win32)
Built-in Camera (Win32)
TV Tuner card (Win32)


Now say for example the camera you wanted to use was "Built-in Camera (Win32)" then this listbox item would be number "1" because the ListBox always starts at "0".

Once youve found the slot number your webcam is in you then need to find your "Private Sub cameraSource()"code and replace it with this:
Code: Select all
Private Sub cameraSource()
        Dim DriverName As String = Space(80)
        Dim DriverVersion As String = Space(80)
        For i As Integer = 0 To 9
            If capGetDriverDescriptionA(i, DriverName, 80, _
               DriverVersion, 80) Then
                ListBox1.Items.Add(DriverName.Trim)
            End If
        Next
        ListBox1.Focus()
        ListBox1.SelectedIndex = 0
    End Sub
The code "ListBox1.SelectedIndex = 0" is the part you need to change to the number of the ListBox slot your webcam is in.

Once youve done that your webcam will automatically start as soon as your application starts.

Hope that helps cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Martin
Supreme VIP
Supreme VIP
Posts: 369
Joined: Sat Aug 01, 2009 12:26 pm

what is this for an program????

martin64 :D
Image
User avatar
Diazepa
VIP - Donator
VIP - Donator
Posts: 70
Joined: Sat Sep 12, 2009 11:38 pm

Thanks :D
Martin - Its a stamp program to kinda "check in" to work, school or similar nerner;

But it don stop there! (Cant bore you ;D) How can i make it mail the picture and that the person logged in?

Preferably not an attachment, but in HTML so its easier to just open the mail, instead of downloading it ^_^

Will the GetUserName statement treat each username different when it is typed into the log, or as 1?
Can i use
Code: Select all
]If form3.textbox1.text then
form3.textbox1.text = form3.textbox1.text + getUsername + "Logged Out!"
else
Form3.textbox1.text = form3.textbox1.text + getUsername + "Logged In!"
Or will it result in every other name in the log becoming in and the other name out

If you get me xD :lol:
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Hello Diazepa,

Can you explain that a little more please because im not sure what you mean. The code I gave you that saves users login/logout to the log file will append the text thats already in the file it wont replace it if that whay you mean :?

To send an email with the captured webcam image use this code, you will need to import:
Code: Select all
Imports System.Net.Mail
Then change your "TextBox1_TextChanged" code to this:
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)
                    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 + " logget seg inn/ut klokken " + 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
            Next
            If GetUsersName = "" Then
                MsgBox("Unregistered", MsgBoxStyle.Critical, "Ops! Uregistrert nummer!")
            End If
        End If
    End Sub
That should work. You need to change the settings ive highlighted with "'Change" to your SMTP server settings and email address.

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

I want to make the
Code: Select all
John doe logged in/out
John doe logged in/out
to
Code: Select all
John doe logged in
john doe logged out
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4390
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Oh I see what you mean, well what code do you use to tell if a user has logged out?.

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

Well
Code: Select all
Form3.textbox1.text = Form3.textbox1.text + GetUserName + "has Logged in/out" + vbNewLine
i use now
26 posts Page 2 of 3
Return to “Tutorial Requests”