<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>vCard &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/vcard/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Mon, 05 Aug 2024 14:41:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>Tutorial: Create QR Codes with vCard Information</title>
		<link>https://blog.xojo.com/2024/08/05/tutorial-create-qr-codes-with-vcard-information/</link>
		
		<dc:creator><![CDATA[Javier Menendez]]></dc:creator>
		<pubDate>Mon, 05 Aug 2024 14:41:37 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Desktop]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[QR Code]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[vCard]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=13391</guid>

					<description><![CDATA[It&#8217;s the 21st Century and it&#8217;s possible to share contacts with other people directly from your mobile phone, but let&#8217;s face it, business cards are&#8230;]]></description>
										<content:encoded><![CDATA[
<p>It&#8217;s the 21st Century and it&#8217;s possible to share contacts with other people directly from your mobile phone, but let&#8217;s face it, business cards are still a very common way to share personal contact information.</p>



<span id="more-13391"></span>



<p>For some years now, it has been common for cards to include a <a href="https://www.qrcode.com/en/">QR code</a> that corresponds to the contact details so that, when scanned, they can be added directly to the Address Book on a device or computer.</p>



<p>This tutorial creates an app that generates QR codes with the embedded information in vCard format. Additionally, learn how to to export that file in vCard format and, if you want, include an image like a contact photograph or logo.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img fetchpriority="high" decoding="async" width="2451" height="1488" src="https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp.png" alt="" class="wp-image-13405" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp.png 2451w, https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp-300x182.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp-1024x622.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp-768x466.png 768w, https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp-1536x933.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/07/CompletedApp-2048x1243.png 2048w" sizes="(max-width: 2451px) 100vw, 2451px" /></figure>
</div>


<p>Download <a href="https://www.xojo.com/download">Xojo</a> and install it on your computer just as you would do with any other application on your operating system of choice (macOS, Windows or Linux).</p>



<p>Once Xojo is installed, launch it and select Desktop in the Choose a Project window. Enter the desired name for this application, as well as the name of the company, etc. You can leave the values presented as default or change them to those of your choice.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" width="1762" height="1182" src="https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector.png" alt="" class="wp-image-13392" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector.png 1762w, https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector-300x201.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector-1024x687.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector-768x515.png 768w, https://blog.xojo.com/wp-content/uploads/2024/07/1-ProjectSelector-1536x1030.png 1536w" sizes="(max-width: 1762px) 100vw, 1762px" /></figure>
</div>


<h2 class="wp-block-heading">Designing the User Interface</h2>



<p>This is the process that will likely take us the longest (with the most steps required). Through this process we will see how to use the Container control to our advantage to compartmentalize different aspects of the UI and also the logic associated with each of these components. Let&#8217;s get started!</p>



<h3 class="wp-block-heading">Personal Data Container</h3>



<p>Click the Library button to access the library that displays all of the user interface controls included by default in Xojo for Desktop projects.</p>



<p>Locate the Container control and drag it onto the Project Navigator. This is the vertical area on the left side of the IDE window where all the elements added to the project are displayed.</p>



<p>When you release the control over the Project Navigator you will see that it is added as a new component and the associated Inspector Panel will appear in the right area of the IDE window. Change the following values using the Inspector Panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PersonalInfoContainer</li>



<li><strong>Width:</strong> 374</li>



<li><strong>Height:</strong> 302</li>
</ul>



<p>With the PersonalInfoContainer control still selected in the Navigator, access the Layout Editor for that control by clicking on the Library icon again. Locate the GroupBox control and double-click on it so it is automatically added to the Layout Editor for the container. Use the following values in the associated Inspector Panel:</p>



<ul class="wp-block-list">
<li><strong>Left:</strong> 0</li>



<li><strong>Top:</strong> 0</li>



<li><strong>Width:</strong> 374</li>



<li><strong>Height:</strong> 302</li>



<li><strong>Locking:</strong> Close the four locks</li>



<li><strong>Caption:</strong> Personal Information</li>
</ul>



<p>Next we will add both the labels and the text fields on the GroupBox1 control so the user can enter the data from which both the vCard and the QR will be created with said information.</p>



<p>Add Label and TextField controls from the library so the user interface looks like this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img decoding="async" width="1064" height="1016" src="https://blog.xojo.com/wp-content/uploads/2024/07/2-PersonalInfoLabels.png" alt="" class="wp-image-13393" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/2-PersonalInfoLabels.png 1064w, https://blog.xojo.com/wp-content/uploads/2024/07/2-PersonalInfoLabels-300x286.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/2-PersonalInfoLabels-1024x978.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/2-PersonalInfoLabels-768x733.png 768w" sizes="(max-width: 1064px) 100vw, 1064px" /></figure>
</div>


<p>Select all the Label items and change the following attribute in the Inspector panel (the change will be applied to all the selection):</p>



<ul class="wp-block-list">
<li><strong>Text Alignment:</strong> Right</li>
</ul>



<p>Next, enter the following values for each of the Labels, selecting them one by one from the top to the bottom:</p>



<p><strong>Label1</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> NameLB</li>



<li><strong>Text:</strong> Name:</li>
</ul>



<p><strong>Label2</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> SurnameLB</li>



<li><strong>Text:</strong> Surname:</li>
</ul>



<p><strong>Label3</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CompanyLB</li>



<li><strong>Text:</strong> Company:</li>
</ul>



<p><strong>Label4</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> TitleLB</li>



<li><strong>Text:</strong> Title:</li>
</ul>



<p><strong>Label5</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PhoneLB</li>



<li><strong>Text:</strong> Phone:</li>
</ul>



<p><strong>Label6</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> MobileLB</li>



<li><strong>Text:</strong> Mobile:</li>
</ul>



<p><strong>Label7</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> EmailLB</li>



<li><strong>Text:</strong> Email:</li>
</ul>



<p><strong>Label8</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> WebLB</li>



<li><strong>Text:</strong> Web:</li>
</ul>



<p>Next, select each of the Textfields, starting from the top, and enter the following values in the inspector panel associated with each of them:</p>



<p><strong>TextField1</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> NameTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p>TextField2</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> SurnameTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p>TextField3</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CompanyTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField4</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> TitleTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p>TextField5</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PhoneTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField6</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> MobileTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField7</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> EmailTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField8</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> WebTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p>When you&#8217;re done, the PersonalInfoContainer&#8217;s user interface will look like this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1000" height="898" src="https://blog.xojo.com/wp-content/uploads/2024/07/3-PersonalInfoCompleted.png" alt="" class="wp-image-13394" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/3-PersonalInfoCompleted.png 1000w, https://blog.xojo.com/wp-content/uploads/2024/07/3-PersonalInfoCompleted-300x269.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/3-PersonalInfoCompleted-768x690.png 768w" sizes="auto, (max-width: 1000px) 100vw, 1000px" /></figure>
</div>


<h3 class="wp-block-heading">Postal Address Container</h3>



<p>We&#8217;re done with the design of the container that will be used to enter the personal information data. Now, add a new Container to the Project Navigator and select it to access the associated Layout Editor.</p>



<p>Use the Inspector Panel to change the following values:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PostalContainer</li>



<li><strong>Width:</strong> 398</li>



<li><strong>Height:</strong> 212</li>
</ul>



<p>Next, double-click the GroupBox control in the Library to add it to the new container, and change the following values using the associated inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Left:</strong> 0</li>



<li><strong>Top:</strong> 0</li>



<li><strong>Width:</strong> 398</li>



<li><strong>Height:</strong> 212</li>



<li><strong>Locking:</strong> Close the four locks.</li>



<li><strong>Caption:</strong> Postal Address:</li>
</ul>



<p>Like we did in the previous container, this time add a total of five labels and as many text fields. The result should be similar to this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="946" height="572" src="https://blog.xojo.com/wp-content/uploads/2024/07/4-PostalContainerLabels.png" alt="" class="wp-image-13395" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/4-PostalContainerLabels.png 946w, https://blog.xojo.com/wp-content/uploads/2024/07/4-PostalContainerLabels-300x181.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/4-PostalContainerLabels-768x464.png 768w" sizes="auto, (max-width: 946px) 100vw, 946px" /></figure>
</div>


<p>Align all labels to the right, just like we did with the previous Container. Then, from top to bottom, modify the following properties for each of them:</p>



<p><strong>Label1</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> StreetLB</li>



<li><strong>Text:</strong> Street:</li>
</ul>



<p><strong>Label2</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PostcodeLB</li>



<li><strong>Text:</strong> Postcode:</li>
</ul>



<p><strong>Label3</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CityLB</li>



<li><strong>Text:</strong> City:</li>
</ul>



<p><strong>Label4</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> ProvinceLB</li>



<li><strong>Text:</strong> Province:</li>
</ul>



<p><strong>Label5</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CountryLB</li>



<li><strong>Text:</strong> Country or Region:</li>
</ul>



<p>And change the following values in the inspector panel for each of the TextFields, also from top to bottom</p>



<p><strong>TextField1</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> StreetTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField2</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PostalCodeTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField3</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CityTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField4</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> ProvinceTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p><strong>TextField5</strong></p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CountryTF</li>



<li><strong>Locking:</strong> Close the left, top and right locks.</li>
</ul>



<p>Once completed, the layout for the PostalContainer container will look similar to this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1044" height="602" src="https://blog.xojo.com/wp-content/uploads/2024/07/5-PostalContainerCompleted.png" alt="" class="wp-image-13396" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/5-PostalContainerCompleted.png 1044w, https://blog.xojo.com/wp-content/uploads/2024/07/5-PostalContainerCompleted-300x173.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/5-PostalContainerCompleted-1024x590.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/5-PostalContainerCompleted-768x443.png 768w" sizes="auto, (max-width: 1044px) 100vw, 1044px" /></figure>
</div>


<h3 class="wp-block-heading">Completing the UI Design</h3>



<p>With the design of the two containers completed, it is time to add them to the main window of the project (Window1), as well as some remaining controls.</p>



<p>Start by selecting the Window1 item in the Navigator to display it in the Layout Editor. Next, drag the PersonalInfoContainer container and drop it onto the top of the right side of the window in the Layout Editor. It should look like this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1326" height="1028" src="https://blog.xojo.com/wp-content/uploads/2024/07/6-PersonalContainerWindow.png" alt="" class="wp-image-13397" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/6-PersonalContainerWindow.png 1326w, https://blog.xojo.com/wp-content/uploads/2024/07/6-PersonalContainerWindow-300x233.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/6-PersonalContainerWindow-1024x794.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/6-PersonalContainerWindow-768x595.png 768w" sizes="auto, (max-width: 1326px) 100vw, 1326px" /></figure>
</div>


<p>With the Window1 item still selected in the Navigator, it is a good time to change some of its properties in the associated Inspector:</p>



<ul class="wp-block-list">
<li><strong>Width:</strong> 600</li>



<li><strong>Height:</strong> 604</li>



<li><strong>Minimum Width:</strong> 600</li>



<li><strong>Minimum Height:</strong> 604</li>



<li><strong>Maximum Width:</strong> 600</li>



<li><strong>Maximum Height:</strong> 604</li>



<li><strong>Title:</strong> QR From vCard &#8211; vCard Export</li>
</ul>



<p>Now, select the PostalContainer container and drop it just below the PersonalInfoContainer container in the Layout Editor for Window1. The result should look like this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1356" height="1406" src="https://blog.xojo.com/wp-content/uploads/2024/07/7-PostalContainerWindow.png" alt="" class="wp-image-13398" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/7-PostalContainerWindow.png 1356w, https://blog.xojo.com/wp-content/uploads/2024/07/7-PostalContainerWindow-289x300.png 289w, https://blog.xojo.com/wp-content/uploads/2024/07/7-PostalContainerWindow-988x1024.png 988w, https://blog.xojo.com/wp-content/uploads/2024/07/7-PostalContainerWindow-768x796.png 768w" sizes="auto, (max-width: 1356px) 100vw, 1356px" /></figure>
</div>


<p>As you can see, the PostalContainer1 container is slightly wider than the PersonalInfoContainer1 item. Select the latter in the Window1 layout editor and use the left middle handle to drag it to the left until the alignment guide appears. This will mean that both containers are aligned.</p>



<p>Now, continue adding the necessary controls to finish the UI:</p>



<ul class="wp-block-list">
<li>An ImageWell control to display the image selected by the user for the vCard.</li>



<li>A button that, when pressed, allows the user to select the image to use in the vCard.</li>



<li>An ImageWell control that displays the preview of the QR generated from the vCard.</li>



<li>A button that, when pressed, allows you to create the QR from the vCard as well as assign the resulting image to the preview control.</li>



<li>A button that, when activated, allows the QR to be exported as an image file in PNG format.</li>



<li>A button that, when pressed, generates the vCard as a file with the selected name and location.</li>



<li>A last button that, when pressed, resets the UI to its default values.</li>
</ul>



<h3 class="wp-block-heading">Selecting the Contact Image</h3>



<p>The contact image selected by the user will be added as part of the vCard generated as a file but not to the QR code because it does not have enough room to accommodate such a large amount of information.</p>



<p>To do this we need to add two controls to Window1: an ImageWell and a Button. Start by adding an ImageWell control to the top left area of the Window1 window in the Layout Editor:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1276" height="1368" src="https://blog.xojo.com/wp-content/uploads/2024/07/8-ImageWellContactWindow.png" alt="" class="wp-image-13399" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/8-ImageWellContactWindow.png 1276w, https://blog.xojo.com/wp-content/uploads/2024/07/8-ImageWellContactWindow-280x300.png 280w, https://blog.xojo.com/wp-content/uploads/2024/07/8-ImageWellContactWindow-955x1024.png 955w, https://blog.xojo.com/wp-content/uploads/2024/07/8-ImageWellContactWindow-768x823.png 768w" sizes="auto, (max-width: 1276px) 100vw, 1276px" /></figure>
</div>


<p>Use the inspector panel associated with that control to change the following values:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> PersonPreview</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 20</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 150</li>
</ul>



<p>Next, drop a Button control just below the PersonPreview and use the associated inspector panel to modify the following values:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> OpenPictureBT</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 182</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 20</li>



<li><strong>Caption:</strong> Open Picture…</li>
</ul>



<p>The result should look something like this:</p>



<figure class="wp-block-image"><img loading="lazy" decoding="async" width="1370" height="1414" src="https://blog.xojo.com/wp-content/uploads/2024/07/9-OpenPictureBT.png" alt="" class="wp-image-13400" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/9-OpenPictureBT.png 1370w, https://blog.xojo.com/wp-content/uploads/2024/07/9-OpenPictureBT-291x300.png 291w, https://blog.xojo.com/wp-content/uploads/2024/07/9-OpenPictureBT-992x1024.png 992w, https://blog.xojo.com/wp-content/uploads/2024/07/9-OpenPictureBT-768x793.png 768w" sizes="auto, (max-width: 1370px) 100vw, 1370px" /></figure>



<h3 class="wp-block-heading">QR Preview and Export</h3>



<p>Now, continue with the UI items corresponding to the QR code preview and the buttons to create it, export the QR or export the vCard.</p>



<p>Drop a new ImageWell control from the library onto Window1 in the Layout Editor and modify the following attributes in the associated inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> QRPreview</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 304</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 150</li>
</ul>



<p>Add a button just below QRPreview and use the following values in the associated Inspector Panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> CreateQRBT</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 466</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 20</li>



<li><strong>Caption:</strong> Create QR</li>
</ul>



<p>Add a new button under CreateQRBT and modify the following values in the inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> ExportQRBT</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 498</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 20</li>



<li><strong>Caption:</strong> Export QR</li>



<li><strong>Enabled:</strong> Desactivado</li>
</ul>



<p>Add a new button just below ExportQRBT and modify the following values in the inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> ExportVCardBT</li>



<li><strong>Left:</strong> 20</li>



<li><strong>Top:</strong> 530</li>



<li><strong>Width:</strong> 150</li>



<li><strong>Height:</strong> 20</li>



<li><strong>Caption:</strong> Export vCard</li>
</ul>



<p>Add the last of the required buttons, just below the PostalContainer1 container and use the following values in the inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Name:</strong> ClearBT</li>



<li><strong>Left:</strong> 500</li>



<li><strong>Top:</strong> 562</li>



<li><strong>Width:</strong> 80</li>



<li><strong>Height:</strong> 20</li>



<li><strong>Locking:</strong> Close the bottom and right locks.</li>



<li><strong>Caption:</strong> Clear</li>
</ul>



<p>We have completed the UI design! This is how it should look:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="1340" height="1398" src="https://blog.xojo.com/wp-content/uploads/2024/07/10-Completed-UI.png" alt="" class="wp-image-13401" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/10-Completed-UI.png 1340w, https://blog.xojo.com/wp-content/uploads/2024/07/10-Completed-UI-288x300.png 288w, https://blog.xojo.com/wp-content/uploads/2024/07/10-Completed-UI-982x1024.png 982w, https://blog.xojo.com/wp-content/uploads/2024/07/10-Completed-UI-768x801.png 768w" sizes="auto, (max-width: 1340px) 100vw, 1340px" /></figure>
</div>


<h2 class="wp-block-heading">Adding Functionality to the PersonalInfoContainer</h2>



<p>It&#8217;s time to add the code (functionality) to each of the components that need it. Start with PersonalInfoContainer, select it in the Navigator. With PersonalInfoContainer1 selected, choose the Insert &gt; Method menu option and use the following values in the associated inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> GetPersonalInformation</li>



<li><strong>Return Type:</strong> String</li>



<li><strong>Scope:</strong> Public</li>
</ul>



<p>Adding the following code in the Code Editor associated with the newly added method:</p>



<pre class="wp-block-code"><code>Var fullName As String = Nametf.Text + " " + SurnameTF.Text

Var returnedValues() As String

If fullname.ReplaceAll(" ", "") &lt;> "" Then returnedValues.Add("FN:" + fullName)
If SurnameTF.Text &lt;> "" Or nametf.Text &lt;> "" Then returnedValues.Add("N:" + SurnameTF.Text + ";" + NameTF.Text + ";;;")
If CompanyTF.Text &lt;> "" Then returnedValues.Add("ORG:" + CompanyTF.Text + ";")
If TitleTF.Text &lt;> "" Then returnedValues.Add("TITLE:" + TitleTF.Text)
If PhoneTF.Text &lt;> "" Then returnedValues.Add("TEL;Type=HOME:" + PhoneTF.Text)
If MobileTF.Text &lt;> "" Then returnedValues.Add("TEL;Type=CELL:" + MobileTF.Text)
If EmailTF.Text &lt;> "" Then returnedValues.Add("EMAIL;Type=INTERNET;type=WORK;type=pref:" + EmailTF.Text)
If WebTF.Text &lt;> "" Then returnedValues.Add("URL:" + WebTF.Text)

Return String.FromArray(returnedValues, EndOfLine)</code></pre>



<p>As you can see, the code for this method is pretty easy to follow. Basically, only the fields in the vCard whose TextField contains values (i.e. are not empty) will be added to the ReturnedValues array. Similarly, and to keep the code as short as possible, this tutorial does not perform any kind of validation on the entered data.</p>



<p>Add a new method to PersonalInfoContainer that will be responsible for cleaning up the UI of that container; use the following values using the Inspector associated with the new method:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> Clear</li>



<li><strong>Scope:</strong> Public</li>
</ul>



<p>And type the following code in the associated Code Editor for the Clear method:</p>



<pre class="wp-block-code"><code>For Each ctl As DesktopUIControl In Self.Controls
  If ctl IsA DesktopTextField Then
    DesktopTextField(ctl).Text = ""
  End If
Next</code></pre>



<p>As you can see, this code loops through all the controls in the PersonalInfoContainer and uses the IsA keyword to check if the iterated control is a DesktopTextField. If it is, it then casts the iterated control to the DesktopTextField class to access its Text property and assign to it the empty string value (&#8220;&#8221;).</p>



<h3 class="wp-block-heading">Add Functionality to the PostalContainer</h3>



<p>Select the PostalContainer container in the Project Navigator. You will see that the functionality is very similar to that added in the previous one.</p>



<p>Create a new method and use the associated panel to change the following values:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> GetPostalInformation</li>



<li><strong>Return Type:</strong> String</li>



<li><strong>Scope:</strong> Public</li>
</ul>



<p>And type the following code in the Code Editor associated with the method:</p>



<pre class="wp-block-code"><code>Var returnedValue As String
Var inputValues() As String

inputValues.Add(StreetTF.Text)
inputValues.Add(CityTF.Text)
inputValues.Add(ProvinceTF.Text)
inputValues.Add(PostalCodeTF.Text)
inputValues.Add(CountryTF.Text)

Var address As String = String.FromArray(inputValues, ";")

If address.ReplaceAll(";","") &lt;> "" Then returnedValue = "ADR;type=WORK:;;" + address

Return returnedValue</code></pre>



<p>As you can see, it is very similar to the one above. The result will be the one corresponding to the &#8220;ADR&#8221; field of a vCard.</p>



<p>Add a second method with the following values in the inspector panel:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> Clear</li>



<li><strong>Scope:</strong> Public</li>
</ul>



<p>And write the following code in the associated editor:</p>



<pre class="wp-block-code"><code>For Each ctl As DesktopUIControl In Self.Controls
  If ctl IsA DesktopTextField Then
    DesktopTextField(ctl).Text = ""
  End If
Next</code></pre>



<p>In this case, the code is the same as the one used in the previous container when &#8220;resetting&#8221; its UI to the initial values.</p>



<h3 class="wp-block-heading">Add General Functionality to the Window</h3>



<p>Select Window1 in the Project Navigator and add a method using the following values using the Inspector Panel:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> GenerateVCARD</li>



<li><strong>Parameters:</strong> forVCardExport as Boolean = False</li>



<li><strong>Return Type:</strong> String</li>
</ul>



<p>And type the following code in the associated Code Editor:</p>



<pre class="wp-block-code"><code>Var vCard() As String
vCard.Add("BEGIN:VCARD")
vCard.Add("VERSION:3.0")
vCard.Add(PersonalInfoContainer1.GetPersonalInformation)
vCard.Add(PostalContainer1.GetPostalInformation)
If PersonPreview.Image &lt;> Nil And forVCardExport Then
  vCard.Add("PHOTO;ENCODING=BASE64;TYPE=JPEG:" + getPersonImage)
End If
vCard.Add("REV:" + GetRevisionTime)
vCard.Add("END:VCARD")

Return String.FromArray(vCard, EndOfLine)</code></pre>



<p>Add a second method with the following values:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> GetRevisionTime</li>



<li><strong>Return Type:</strong> String</li>
</ul>



<p>And type the following lines of code in the associated code editor:</p>



<pre class="wp-block-code"><code>Var current As DateTime = DateTime.Now
Var currentToUTC As DateTime = New DateTime(current.SecondsFrom1970 - current.Timezone.SecondsFromGMT)

Return currentToUTC.Year.ToString + currentToUTC.Month.ToString + currentToUTC.Day.ToString + "T" + currentToUTC.Hour.ToString + currentToUTC.Minute.ToString + currentToUTC.Second.ToString + "Z"</code></pre>



<p>Add the last of the general methods and use the following values in the Inspector:</p>



<ul class="wp-block-list">
<li><strong>Method Name:</strong> GetPersonImage</li>



<li><strong>Return Type:</strong> String</li>
</ul>



<p>Next, enter the following code into the associated editor:</p>



<pre class="wp-block-code"><code>Var returnedValue As String

Const kWidth as Double = 120
var pHeight as Double

If PersonPreview.Image &lt;> Nil Then
  
  pHeight = (kWidth * PersonPreview.Image.Height) / PersonPreview.Image.Width
  
  Var tempPic As New Picture(kWidth, pHeight)
  tempPic.Graphics.DrawPicture(PersonPreview.Image, 0, 0, kWidth, pHeight, 0, 0, PersonPreview.Image.Width, PersonPreview.Image.Height)
  
  Var mb As MemoryBlock = TempPic.ToData(Picture.Formats.JPEG)
  
  returnedValue = EncodeBase64(mb)
  returnedValue = returnedValue.ReplaceLineEndings("")
End If

Return returnedValue</code></pre>



<h3 class="wp-block-heading">Adding Specific Functionality to Controls</h3>



<p>We just need to add the functionality that will be executed when the different buttons are pressed. Start by selecting ClearBT in the Project Navigator then select the &#8220;Add to &#8216;ClearBT&#8217; &gt; Event Handler…&#8221; option in the context menu. Choose the Pressed event in the resulting window and confirm the selection so that this event is added to the control.</p>



<p>Now, enter the following code in the code editor associated with the Pressed event of the ClearBT control:</p>



<pre class="wp-block-code"><code>PersonPreview.Image = Nil
QRPreview.Image = Nil
ExportQRBT.Enabled = False

PersonalInfoContainer1.Clear
PostalContainer1.Clear</code></pre>



<p>Add the Pressed event to the CreateQRBT control and type the following code in the associated code editor:</p>



<pre class="wp-block-code"><code>QRPreview.Image = Nil

Var theCard As String = GenerateVCARD

Try
  Var p As Picture = Barcode.Image(theCard, 600, 600)
  
  If p &lt;&gt; Nil Then
    QRPreview.Image = p
    ExportQRBT.Enabled = True
  Else
    ExportQRBT.Enabled = False
  End If
  
Catch e As UnsupportedOperationException
  
  MessageBox("Unable to Create QR" + EndOfLine + EndOfLine + "Probably the provided data exceeds the available room for a QR.")
  
End Try</code></pre>



<p>Add the Pressed event to the ExportQRBT control and enter the following code in the associated code editor:</p>



<pre class="wp-block-code"><code>If QRPreview.Image &lt;&gt; Nil Then
  
  Var f As FolderItem = FolderItem.ShowSaveFileDialog("", "ExportedQR.PNG")
  
  If f &lt;&gt; Nil Then
    
    QRPreview.Image.Save(f, Picture.Formats.PNG)
    
  End If
  
End If</code></pre>



<p>Add the Pressed event to the ExportVCardBT control and enter the following code in the associated Code Editor:</p>



<pre class="wp-block-code"><code>Var theCard As String = GenerateVCARD(True)

Var f As FolderItem = FolderItem.ShowSaveFileDialog("", "Exported.vCard")

If f &lt;> Nil Then
  Var tos As TextOutputStream = TextOutputStream.Create(f)
  
  tos.Write(theCard)
  tos.Flush
  tos.Close
End If</code></pre>



<p>Add the Pressed event to the OpenPictureBT control and type the following code using the associated Code Editor:</p>



<pre class="wp-block-code"><code>PersonPreview.Image = Nil

Var f As FolderItem = FolderItem.ShowOpenFileDialog(SupportedImageFormats.All)

If f &lt;> Nil Then
  PersonPreview.Image = Picture.Open(f)
End If</code></pre>



<h2 class="wp-block-heading">Files Filtering</h2>



<p>As you can see, in the second line of the above code we reference the SupportedImageFormats.All object as a parameter to filter the type of files that the user can select.</p>



<p>To do this, add a new File Type Group from Insert &gt; File Type Group. With the newly added item in the Project Navigator selected, click the leftmost button in the toolbar to add the &#8220;image/jpeg&#8221; entry. Repeat this to add &#8220;image/png&#8221; as well.</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="2584" height="784" src="https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter.png" alt="" class="wp-image-13402" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter.png 2584w, https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter-300x91.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter-1024x311.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter-768x233.png 768w, https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter-1536x466.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/07/11.FileTypeFilter-2048x621.png 2048w" sizes="auto, (max-width: 2584px) 100vw, 2584px" /></figure>
</div>


<p>Finally, in the inspector panel change the name of the item to SupportedImageFormats. Once finished, it should look like this:</p>


<div class="wp-block-image">
<figure class="aligncenter"><img loading="lazy" decoding="async" width="2294" height="1388" src="https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted.png" alt="" class="wp-image-13403" srcset="https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted.png 2294w, https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted-300x182.png 300w, https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted-1024x620.png 1024w, https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted-768x465.png 768w, https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted-1536x929.png 1536w, https://blog.xojo.com/wp-content/uploads/2024/07/12-ImageFilterCompleted-2048x1239.png 2048w" sizes="auto, (max-width: 2294px) 100vw, 2294px" /></figure>
</div>


<h2 class="wp-block-heading">Let&#8217;s Go!</h2>



<p>Now the design and the functionality of our app are both completed! Let&#8217;s run it and do some tests. Try selecting a contact image (or not), filling in any of the fields, generating the associated QR and exporting it … or exporting the vCard file directly so that you can import it from any compatible application (for example, Contacts on macOS).</p>



<p>Of course, you can expand and complete this small example: from introducing validations for the fields that require it, increasing the number of fields so that the vCard also includes any other fields supported by the standard, etc.</p>



<h2 class="wp-block-heading">Conclusion</h2>



<p>As you have seen, generating both the vCard and the QR that contains contact information does not require a large amount of code. Best of all, with Xojo, you can check a box and cross-compile your app for macOS, Windows and Linux.</p>



<p>Happy Xojo Coding!</p>



<p><em>Javier Menendez is an engineer at Xojo and has been using Xojo since 1998. He lives in Castellón</em>, <em>Spain and hosts regular Xojo hangouts en español. Ask Javier questions on Twitter at <a href="https://twitter.com/xojoes" target="_blank" rel="noreferrer noopener">@XojoES</a> or on the <a href="https://forum.xojo.com/u/javier_menendez/summary" target="_blank" rel="noreferrer noopener">Xojo Forum</a>.</em></p>



<ul class="wp-block-social-links has-normal-icon-size is-content-justification-center is-layout-flex wp-container-core-social-links-is-layout-16018d1d wp-block-social-links-is-layout-flex"><li class="wp-social-link wp-social-link-facebook  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.facebook.com/goxojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12 2C6.5 2 2 6.5 2 12c0 5 3.7 9.1 8.4 9.9v-7H7.9V12h2.5V9.8c0-2.5 1.5-3.9 3.8-3.9 1.1 0 2.2.2 2.2.2v2.5h-1.3c-1.2 0-1.6.8-1.6 1.6V12h2.8l-.4 2.9h-2.3v7C18.3 21.1 22 17 22 12c0-5.5-4.5-10-10-10z"></path></svg><span class="wp-block-social-link-label screen-reader-text">Facebook</span></a></li>

<li class="wp-social-link wp-social-link-x  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://x.com/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M13.982 10.622 20.54 3h-1.554l-5.693 6.618L8.745 3H3.5l6.876 10.007L3.5 21h1.554l6.012-6.989L15.868 21h5.245l-7.131-10.378Zm-2.128 2.474-.697-.997-5.543-7.93H8l4.474 6.4.697.996 5.815 8.318h-2.387l-4.745-6.787Z" /></svg><span class="wp-block-social-link-label screen-reader-text">X</span></a></li>

<li class="wp-social-link wp-social-link-linkedin  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.linkedin.com/company/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M19.7,3H4.3C3.582,3,3,3.582,3,4.3v15.4C3,20.418,3.582,21,4.3,21h15.4c0.718,0,1.3-0.582,1.3-1.3V4.3 C21,3.582,20.418,3,19.7,3z M8.339,18.338H5.667v-8.59h2.672V18.338z M7.004,8.574c-0.857,0-1.549-0.694-1.549-1.548 c0-0.855,0.691-1.548,1.549-1.548c0.854,0,1.547,0.694,1.547,1.548C8.551,7.881,7.858,8.574,7.004,8.574z M18.339,18.338h-2.669 v-4.177c0-0.996-0.017-2.278-1.387-2.278c-1.389,0-1.601,1.086-1.601,2.206v4.249h-2.667v-8.59h2.559v1.174h0.037 c0.356-0.675,1.227-1.387,2.526-1.387c2.703,0,3.203,1.779,3.203,4.092V18.338z"></path></svg><span class="wp-block-social-link-label screen-reader-text">LinkedIn</span></a></li>

<li class="wp-social-link wp-social-link-github  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://github.com/topics/xojo" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M12,2C6.477,2,2,6.477,2,12c0,4.419,2.865,8.166,6.839,9.489c0.5,0.09,0.682-0.218,0.682-0.484 c0-0.236-0.009-0.866-0.014-1.699c-2.782,0.602-3.369-1.34-3.369-1.34c-0.455-1.157-1.11-1.465-1.11-1.465 c-0.909-0.62,0.069-0.608,0.069-0.608c1.004,0.071,1.532,1.03,1.532,1.03c0.891,1.529,2.341,1.089,2.91,0.833 c0.091-0.647,0.349-1.086,0.635-1.337c-2.22-0.251-4.555-1.111-4.555-4.943c0-1.091,0.39-1.984,1.03-2.682 C6.546,8.54,6.202,7.524,6.746,6.148c0,0,0.84-0.269,2.75,1.025C10.295,6.95,11.15,6.84,12,6.836 c0.85,0.004,1.705,0.114,2.504,0.336c1.909-1.294,2.748-1.025,2.748-1.025c0.546,1.376,0.202,2.394,0.1,2.646 c0.64,0.699,1.026,1.591,1.026,2.682c0,3.841-2.337,4.687-4.565,4.935c0.359,0.307,0.679,0.917,0.679,1.852 c0,1.335-0.012,2.415-0.012,2.741c0,0.269,0.18,0.579,0.688,0.481C19.138,20.161,22,16.416,22,12C22,6.477,17.523,2,12,2z"></path></svg><span class="wp-block-social-link-label screen-reader-text">GitHub</span></a></li>

<li class="wp-social-link wp-social-link-youtube  wp-block-social-link"><a rel="noopener nofollow" target="_blank" href="https://www.youtube.com/c/XojoInc" class="wp-block-social-link-anchor"><svg width="24" height="24" viewBox="0 0 24 24" version="1.1" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false"><path d="M21.8,8.001c0,0-0.195-1.378-0.795-1.985c-0.76-0.797-1.613-0.801-2.004-0.847c-2.799-0.202-6.997-0.202-6.997-0.202 h-0.009c0,0-4.198,0-6.997,0.202C4.608,5.216,3.756,5.22,2.995,6.016C2.395,6.623,2.2,8.001,2.2,8.001S2,9.62,2,11.238v1.517 c0,1.618,0.2,3.237,0.2,3.237s0.195,1.378,0.795,1.985c0.761,0.797,1.76,0.771,2.205,0.855c1.6,0.153,6.8,0.201,6.8,0.201 s4.203-0.006,7.001-0.209c0.391-0.047,1.243-0.051,2.004-0.847c0.6-0.607,0.795-1.985,0.795-1.985s0.2-1.618,0.2-3.237v-1.517 C22,9.62,21.8,8.001,21.8,8.001z M9.935,14.594l-0.001-5.62l5.404,2.82L9.935,14.594z"></path></svg><span class="wp-block-social-link-label screen-reader-text">YouTube</span></a></li></ul>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
