Click here to Skip to main content
15,886,060 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I will try to give better explanation of my problem:
This is a V-Card file (vcf) all this info will be showing in my app.
There is only one line that is not working. I have tried a lot to get this right.

CSS
BEGIN:VCard
VERSION:2.1
N:De Jong
FN:Anne
TEL;WORK;VOICE:0512540540
TEL;WORK;VOICE:0512540540
TEL;HOME;VOICE:06-11299731
TEL;CELL;VOICE:06-11299731
TEL;VOICE:0512 540221
TEL;WORK;FAX:0512 540540
TEL;FAX:0512 540221

ADR;WORK;PREF:;;Sjoerd Veltmanstraat 15;Drachten;;9203 NJ
ENCODING=QUOTED-PRINTABLE:Sjoerd Veltmanstraat 15

URL;HOME:www.epixfotostudio.nl
URL;WORK:www.epixfotostudio.nl
EMAIL;PREF;INTERNET:odejong@epixfotostudio.nl
END:VCARD


ADR;WORK;PREF:;;Sjoerd Veltmanstraat 15;Drachten;;9203 NJ
This is the line I need to show.

This is my code:

VB
'Private Sub voor het importeren van een V-Card:
Private Sub Importeren() _
    Handles itemImporteerVCard.Click, mnuImportVCard.Click, _
    btnImportVCard.Click                                    'Alle knoppen voor het importeren:

    Dim strBestand As String = " "                          'Locatie + naam van het bestand:
    Dim strRegel As String = String.Empty                   'Regel/lijn:
    Dim strWaarde() As String = Nothing                     'de inhoud van de regels/lijnen:

    Dim objReader As System.IO.StreamReader = Nothing, _
        sbBuilder As System.Text.StringBuilder = Nothing

    'Variabelen:
    '--------------------------------
    Dim intNummer As Integer = "720612"                     'een nummer kan maar één keer voorkomen:
    Dim strSoort As String = "D"                            'D = Debiteuren, C = Crediteuren, R = Relaties:
    Dim strNaam As String = " "                             'de naam die in de V-Card staat:
    Dim strVoornaam As String = " "                         'Voornaam:
    Dim strTelWerk As String = " "                          'Telefoonnummer zakelijk:
    Dim strTelThuis As String = " "                         'Telefoonnummer privé:
    Dim strMobiel As String = " "                           'Mobiel nummer:
    Dim strOverig As String = " "                           'Overige telefoon nummers:
    Dim strFaxWerk As String = " "                          'Fax zakelijk + privé:
    Dim strFaxThuis As String = " "

    Dim strAdres As String = " "
    Dim strPostcode As String = " "
    Dim strPlaats As String = " "
    Dim strAdgegevens As String = strAdres & strPostcode & strPlaats

    Dim strUrlThuis As String = " "                         'Website, privé en zakelijk:
    Dim strUrlWerk As String = " "
    Dim strMail As String = " "                             'E-mail adres:
    Dim strZoek As String = "testtest"                      'Zoeknaam: eerste 4 letters van naam en v.d. woonplaats:

    'Bevestiging voor het importeren:
    If MsgBox _
        ("Wilt u een v-Card Importeren?", 36, "Bevestiging voor het importeren") _
        = MsgBoxResult.Yes Then

        Try
            strBestand = "c:/Test.vcf"                      'Verwijst naar de locatie van het bestand:
            sbBuilder = New System.Text.StringBuilder       'Er is een nieuwe stringbuilder gemaakt:
            frmVCard.txtVCard.Text = strBestand             'frmVcard.txtVcard.Text moet gevuld worden:
            'met de inhoud van het bestand:

            objReader = New System.IO.StreamReader(strBestand)

            'Eigenschappen voor het openen van de V-Card:
            ofdImport.Filter = "V-Cards (*.vcf)|*.vcf"      'Filter betreft de extensie van het bestand *.vcf:
            ofdImport.FileName = "*.vcf"                    'Bestandsnaam: alles.vcf:
            ofdImport.Title = "V-Card importeren"           'Titel van het dialoogvenster voor het openen:

            If ofdImport.ShowDialog = System.Windows.Forms.DialogResult.OK Then

                objReader = New System.IO.StreamReader(strBestand)
                frmVCard.Show()                             'Laat de form zien waar de Vcard in terecht komt:
            End If

            Do While objReader.Peek >= 1
                strRegel = objReader.ReadLine()             'Elke regel/lijn wordt 1 voor 1 gelezen:
                strWaarde = strRegel.Split(":")             'De waarde van elke regel wordt gesplits d.m.v. ":":
                strAdgegevens.Split(strAdres, strPostcode, strPlaats, ";")

                'Onderstaande Boolean zorgt ervoor dat dubbele info weg gehaald worden:
                '----------------------------------------------------------------------
                Dim blnDubbel As Boolean

                Select Case UCase(strWaarde(0))             '(0) = het gedeelte voor ":" en (1) komt daarna:
                    Case "BEGIN", "VERSION", "END", _
                         "ENCODING=QUOTED-PRINTABLE"

                    Case "N"
                        strNaam = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbTab)

                    Case "FN"                               'Voornaam:
                        strVoornaam = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "TEL;WORK;VOICE"                   'Telefoon op het werk:
                        If blnDubbel = False Then

                            strTelWerk = strWaarde(1)
                            sbBuilder.Append(strWaarde(1) & vbTab)
                            blnDubbel = True
                        End If

                    Case "TEL;HOME;VOICE"                   'Telefoon thuis:
                        strTelThuis = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "TEL;CELL;VOICE"                   'Mobiele telefoon:
                        strMobiel = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbTab)

                    Case "TEL;VOICE"                        'Overige nummers:
                        strOverig = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "TEL;WORK;FAX"                     'Fax op het werk:
                        strFaxWerk = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbTab)

                    Case "TEL;FAX"                          'Fax thuis:
                        strFaxThuis = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "ADR;WORK;PREF:"                  'Adresgegevens:
                        strAdgegevens = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "URL;HOME:"                        'Website Thuis:
                        strUrlThuis = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbTab)

                    Case "URL;WORK:"                        'Website Werk:
                        strUrlWerk = strWaarde(1)
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                    Case "EMAIL;PREF;INTERNET:"             'Email adres:
                        strMail = strWaarde(1)
                        sbBuilder.Append(strWaarde(1))

                    Case Else
                        sbBuilder.Append(strWaarde(1) & vbCrLf)

                End Select
            Loop                                            'Het proces wordt herhaald:
            objReader.Close()
            frmVCard.txtVCard.Text = sbBuilder.ToString

            Dim strInsert As String

            'Waardes invoegen in de velden van de tabel Relaties:
            '----------------------------------------------------
            'INSERT & VALUES lijst:

            strInsert = "INSERT INTO Relaties (B22_relnr, B22_rel_soort, B22_naam, B22_voornaam_etc, " _
             & "B22_adres, B22_postcode, B22_plaats, B22_telefoon1, B22_telefoon2, " _
             & "B22_mobielnr, B22_faxnummer, B22_email, B22_www_adres, B22_zoeknaam) " _
             & " VALUES (" & intNummer & ", '" & strSoort & "', '" & strNaam _
             & "', '" & strVoornaam & "', '" & strAdres _
             & "', '" & strPostcode & "', '" & strPlaats & "', '" & strTelWerk _
             & "', '" & strTelThuis & "', '" & strMobiel & "', '" & strFaxWerk _
             & "', '" & strMail & "', '" & strUrlWerk & "', '" & strZoek & "' )"

            Dim ds_B22 As New OdbcCommand                       'ds_B22 is de tabel Relaties.
            ds_B22.CommandType = Data.CommandType.Text
            ds_B22.CommandText = strInsert      'Zorgt ervoor dat de informatie wordt toegevoegd aan de database.
            ds_B22.Connection = cnn
            ds_B22.ExecuteNonQuery()

            If MsgBox _
                ("De V-Card is geïmporteerd", 0, "V-Card is geïmporteerd") Then

                Exit Sub
            End If

        Catch ex As Exception

            MsgBox _
                (ex.Message, MsgBoxStyle.Exclamation, "Fout...")

            'MsgBox _
            '    ("Dit nummer bestaat al", 0, "Fout..!")

        Finally
            objReader.Dispose()
            sbBuilder = Nothing

        End Try
    End If
End Sub

It is a lot of code, I hope that you can understand what my purpose is.
My application can make a V-Card and now I'm trying to insert the V-Card.
The V-Card that I have inserted must send the info inside it.. into the right fields of my database.. That's the part where I'm busy with right now.

In the bold line i Need to Split the ":"and the ";"..but I don't know how to do it..

I hope that someone can help me with this problem.. I've only got a few days to complete my project.

[edit]Code block added - OriginalGriff[/edit]
Posted
Updated 27-Jun-12 23:41pm
v3

1 solution

You can check this article on CP
.NET vCard API for creating and parsing vCards[^]

Try with this lib, why reinventing the wheel?

Cheers again ;)
 
Share this answer
 
v3
Comments
OdeJong 28-Jun-12 6:05am    
I don't know how to send u a private message, but I'm interested in what u have written. So maybe you can send me a few examples of your code.

Greetz
Mario Majčica 28-Jun-12 6:10am    
Well it will be a shame redoing what Ivar Lumi did. Try with this lib http://www.codeproject.com/Articles/16030/NET-vCard-API-for-creating-and-parsing-vCards
Also you have an example project attached on how to use it. It is in C# but converting it to VB should not be a problem (if you really need it converted) http://www.developerfusion.com/tools/convert/csharp-to-vb/.
If you want to contact me in private, check this http://blog.majcica.com/contact/
OdeJong 28-Jun-12 6:38am    
Bedankt! ik zal zien hoe ver ik hiermee kom. ha, ik zie dat je uit Amsterdam komt. Greetz!
Mario Majčica 28-Jun-12 6:47am    
Graag gedaan! Anytime ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900