<?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>VBA Archives | DMC, Inc.</title>
	<atom:link href="https://static.dmcinfo.com/blog/tag/vba/feed/index.xml" rel="self" type="application/rss+xml" />
	<link></link>
	<description></description>
	<lastBuildDate>Thu, 09 Jul 2026 19:11:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.2</generator>

<image>
	<url>https://static.dmcinfo.com/wp-content/uploads/2025/04/site-icon-150x150.png</url>
	<title>VBA Archives | DMC, Inc.</title>
	<link></link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Triggering Popups and Display Changes in FactoryTalk View Site Edition from the PLC</title>
		<link>https://static.dmcinfo.com/blog/17267/triggering-popups-and-display-changes-in-factorytalk-view-site-edition-from-the-plc/</link>
		
		<dc:creator><![CDATA[DMC]]></dc:creator>
		<pubDate>Mon, 28 Aug 2023 18:23:57 +0000</pubDate>
				<category><![CDATA[Allen Bradley PLC]]></category>
		<category><![CDATA[HMI and SCADA]]></category>
		<category><![CDATA[Manufacturing Automation & Intelligence]]></category>
		<category><![CDATA[Display]]></category>
		<category><![CDATA[FactoryTalk]]></category>
		<category><![CDATA[FactoryTalk View SE]]></category>
		<category><![CDATA[FactoryTalk View Site Edition]]></category>
		<category><![CDATA[PLC]]></category>
		<category><![CDATA[Popup]]></category>
		<category><![CDATA[VB]]></category>
		<category><![CDATA[VBA]]></category>
		<category><![CDATA[Visual Basic]]></category>
		<guid isPermaLink="false">https://static.dmcinfo.com/blog/17267/triggering-popups-and-display-changes-in-factorytalk-view-site-edition-from-the-plc/</guid>

					<description><![CDATA[<p>Whether you are migrating from Machine Edition or working with FactoryTalk View for the first time, triggering displays or popups from the PLC in Site Edition is non-trivial. In this blog post, we are going to discuss how to use Visual Basic to our advantage to trigger both display changes and popup displays. Common questions [&#8230;]</p>
<p>The post <a href="https://static.dmcinfo.com/blog/17267/triggering-popups-and-display-changes-in-factorytalk-view-site-edition-from-the-plc/">Triggering Popups and Display Changes in FactoryTalk View Site Edition from the PLC</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p class="wp-block-paragraph">Whether you are migrating from Machine Edition or working with FactoryTalk View for the first time, triggering displays or popups from the PLC in Site Edition is non-trivial. In this blog post, we are going to discuss how to use Visual Basic to our advantage to trigger both display changes and popup displays.</p>



<p class="wp-block-paragraph"><strong>Common questions that may have led you here:</strong></p>


<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">


<p class="wp-block-paragraph"><strong>Why can I do this in Machine Edition but not Site Edition?</strong></p>



<p class="wp-block-paragraph">One major difference between ME and SE is the <a href="https://en.wikipedia.org/wiki/Client%E2%80%93server_model" rel="no follow" target="_blank">Client-server model</a> employed by SE. While ME has one instance of the HMI, SE can have multiple clients connected to the same server that the PLC is connected to. Each of these client instances will appear as its own <a href="https://static.dmcinfo.com/services/manufacturing-automation-and-intelligence/hmi-and-scada-programming"><strong>HMI programming</strong></a> and can be operated independently of the others. This behavior is contrary to ME’s.</p>



<p class="wp-block-paragraph"><strong>Why can&#8217;t I use events to trigger the &#8220;Display&#8221; command?</strong></p>



<p class="wp-block-paragraph">FactoryTalk View Site Edition operates on a <a href="https://en.wikipedia.org/wiki/Client%E2%80%93server_model" rel="no follow" target="_blank">Client-server model</a>. When you run a <code>.cli</code> file, you are running a client connected to a server. When an event triggers, it is done on the server, not the client. The FactoryTalk server is configured to ignore <code><tt>Display</tt> </code>commands run on it.</p>


</div>


<h2 class="wp-block-heading" id="h-the-basics">The Basics</h2>



<p class="wp-block-paragraph">In this section, we will&nbsp;cover how to do the minimum viable work to get display changes working. This process will cover the basics and allow you to get working on your own, but feel free to stick around if you want to improve your coding and architecting skills.</p>



<h3 class="wp-block-heading" id="h-creating-a-trigger">Creating a Trigger</h3>



<p class="wp-block-paragraph">In this section, I am going to explain how to create a global trigger. This just means that we are going to set up a display such that the trigger is always being updated so you can initiate a change from any display.</p>


<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">


<p class="wp-block-paragraph"><strong>That is too vague. Give me the technical description!</strong></p>



<p class="wp-block-paragraph">In order to create a “global trigger,” we are going to employ the assistance of an event-driven VBA subroutine on a screen loaded into cache and being constantly updated.</p>



<p class="wp-block-paragraph">We will create an event-driven VB subroutine by using the <code>Change</code> event on a numeric input component. This numeric input will be put on a screen that is developed specifically to be loaded into cache and constantly updated so that the <code>Change</code> event can be seen at any time. This will be achieved by calling the <code>Display </code>command with the <code>/ZA</code> parameter (see the&nbsp;<a data-sk="tooltip_parent" data-stringify-link="https://literature.rockwellautomation.com/idc/groups/literature/documents/um/viewse-um006_-en-e.pdf#page=313" delay="150" href="https://literature.rockwellautomation.com/idc/groups/literature/documents/um/viewse-um006_-en-e.pdf#page=283" rel="noopener noreferrer" target="_blank">Rockwell Docs</a>&nbsp;for more specifics on the behavior of this command) from a macro run on startup.</p>


</div>


<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Firstly, we are going to create a new display. You can call this display <code>PopupHandler&nbsp;</code>if you want it to be sufficiently descriptive. On this display, we are going to add a numeric input. Set the expression to be your trigger condition.</p></p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/numeric-display-on-popuphandler-display.png" alt="Numeric Display on PopupHandler Display"/></figure>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/sample-expression-for-numeric-display.png" alt="Sample Expression for the Numeric Display"/></figure>


<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">


<p class="wp-block-paragraph"><strong>Multistate Triggers</strong></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 [&quot;expand&quot;,{&quot;title&quot;:&quot;Multistate Triggers&quot;,&quot;__expanded&quot;:true}]">The observant eye might realize our expression is not limited to a 0 or 1; therefore, neither is the behavior of our triggered event. If you have a more multistate tag that you want to link here, feel free to do so. We will address how to change the event by value later in the blog when discussing architecture improvements.</p></p>


</div>


<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Once you’ve got the numeric input set up, right click the background of the display and select <code>Display Settings...</code> . Make sure the following properties match between your displays:</p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []"></p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Now, we are going to make the PopupHandler silently load and stay cached and updated so the numeric input we have created is always loaded. Create a macro and call it <code>startup</code>. When the macro opens, add the following command on a new line:</p></p>


<pre data-pm-slice="1 1 []">
<code>Display PopupHandler /ZA</code></pre>


<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/example-macro-script.png" alt="Example Macro Script"/></figure>


<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">


<p class="wp-block-paragraph"><strong>What does this command do?</strong></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 [&quot;expand&quot;,{&quot;title&quot;:&quot;What does this command do?&quot;,&quot;__expanded&quot;:true}]">This command will load this display into cache and continually update its values. This is important as it will make sure the numeric stays loaded and updated as the client runs.</p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 [&quot;expand&quot;,{&quot;title&quot;:&quot;What does this command do?&quot;,&quot;__expanded&quot;:true}]"><strong>What if I already have a client-side startup macro?</strong></p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 [&quot;expand&quot;,{&quot;title&quot;:&quot;What if I already have a client-side startup macro?&quot;,&quot;__expanded&quot;:true}]">If you already have one, just append this command to the end of the existing macro.</p></p>


</div>


<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Now that we have the macro ready, we are going to add it to our client runtime. Edit your <code>.cli</code> file and make sure you’ve got the <code>startup</code> macro selected to run on startup. Once this is done, the macro should execute on startup and load the <code>PopupHandler</code> display into our cache.</p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 [&quot;expand&quot;,{&quot;title&quot;:&quot;What does this command do?&quot;,&quot;__expanded&quot;:true}]"></p></p>



<h3 class="wp-block-heading" id="h-using-vb-to-set-a-display">Using VB to Set a Display</h3>



<p class="wp-block-paragraph">Now that we have the trigger ready, we are going to add the corresponding VB Script. Select the numeric input on your <code>PopupHandler</code> display, right click, and select <code>VBA Code...</code> . You should see the following:</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/vba-subroutine-definition.png" alt="VBA Subroutine Definition"/></figure>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">The subroutine (<code>sub</code>) you see of the form <code>NumericDisplayName_Change</code> is the script that is going to run when our condition changes. To trigger our display change, we are going to add the following line of code inside the subroutine (replace “DisplayName” with the display you want to appear).</p></p>


<pre data-pm-slice="1 1 []">
<code>ExecuteCommand ("Display DisplayName")</code></pre>


<p class="wp-block-paragraph">With that, you should be ready to go. Go ahead and restart your client and try triggering your condition. Ideally, you should see the popup or display you specified appear when the condition changes. If you do, you’ve got the minimum viable product and should proceed to the &#8220;Let&#8217;s Make it Better&#8221; section to refine your implementation.</p>



<h2 class="wp-block-heading" id="h-let-s-make-it-better">Let’s Make it Better</h2>



<p class="wp-block-paragraph">We can do better and you know it. If you want to impress the&nbsp;future engineers who will look at your work, then I suggest you get&nbsp;to the end of this section.</p>



<h3 class="wp-block-heading" id="h-better-naming-practice">Better Naming Practice</h3>



<p class="wp-block-paragraph">Let’s start by changing the name of our component. Go into the component properties and set the name to something more descriptive —&nbsp;in this case, we will use <code>PopupEventTrigger</code>. If we observe the VB Script again, then we will see the name of the subroutine has been changed to reflect what was done in FactoryTalk View Studio.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/updated-vba-subroutine.png" alt="Updated VBA Subroutine"/></figure>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Let’s also leave a clear visual indication of the work we have done. Next to the numeric input you are using, go ahead and add a text box and describe what is happening here. This will make it readily apparent to other engineers that there is VB Scripting going on behind the scenes.</p></p>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []"></p></p>



<h3 class="wp-block-heading" id="h-case-by-case-events">Case-By-Case Events</h3>



<p class="wp-block-paragraph"><p data-pm-slice="1 1 []">Instead of triggering any time we see the value change, let&#8217;s consider the value we are seeing. In this case, we are going to nest another condition that checks if the value of our trigger is&nbsp;&#8220;1&#8221;. With this new implementation,&nbsp;we should only see our change when we have a rising edge signal.</p></p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(1 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' If trigger value is rising '
    If PopupEventTrigger.Value = 1 Then
        ' Change Display '
        ExecuteCommand ("Display Popup")
    End If
End Sub </textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; If trigger value is rising &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; Change Display &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"><span style="color: #569CD6">End Sub </span></span></code></pre></div>


<div style="background:#eee;border:1px solid #ccc;padding:5px 10px;">


<p class="wp-block-paragraph"><strong>Working with popup displays?</strong></p>



<p class="wp-block-paragraph">If you are working with popup displays, you may want to use triggers to close the popup as well as open it. Well, as luck has it, implementing this functionality is a breeze. In the simplest terms, we need only execute the command <code>Abort DisplayName</code> from our Visual Basic script; however, if we want to get clever, we can reuse our existing condition, closing the popup on a falling edge signal in addition to opening it with a rising edge signal!</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' If trigger value is rising '
    If PopupEventTrigger.Value = 1 Then
        ' Change Display '
        ExecuteCommand ("Display Popup")
    ' If trigger value is falling '
    ElseIf PopupEventTrigger.Value = 0 Then
        ' Close Display '
        ExecuteCommand ("Abort Popup")
    End If
End Sub
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; If trigger value is rising &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; Change Display &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; If trigger value is falling &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">ElseIf</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">0</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; Close Display &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Abort Popup&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"><span style="color: #569CD6">End Sub</span></span>
<span class="line"></span></code></pre></div>



<p class="wp-block-paragraph">Notice that I chose to use an <code>Elsif</code> here instead of an <code>Else</code>. This was intentional, as the value of the numeric display is not limited to 1 nor 0. When deciding how to handle your code, consider what makes the most sense for you based on your intended behavior.</p>


</div>


<h3 class="wp-block-heading" id="h-error-handling">Error Handling</h3>



<p class="wp-block-paragraph">Let&#8217;s prevent errors from interfering with our operation. If there is an issue with the connection to the PLC, then the numeric display may have an error value. Unfortunately for us, this change to an error value counts as a value change and will trigger our display change subroutine. To avoid this, we will wrap our logic in an if statement that checks if there is an error value in our component.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' Make sure there is no error '
    If Not IsError(PopupEventTrigger.Value) Then

        ' If trigger value is rising '
        If PopupEventTrigger.Value = 1 Then
            ' Change Display '
            ExecuteCommand ("Display Popup")
        End If

    End If
End Sub
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; Make sure there is no error &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> Not </span><span style="color: #DCDCAA">IsError</span><span style="color: #D4D4D4">(PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">) </span><span style="color: #C586C0">Then</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; If trigger value is rising &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #6A9955">&apos; Change Display &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">End If</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"><span style="color: #569CD6">End Sub</span></span>
<span class="line"></span></code></pre></div>



<p class="wp-block-paragraph">Alternatively, we could exit the subroutine early if there is an error.</p>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' Make sure there is no error '
    If IsError(PopupEventTrigger.Value) Then
        Exit Sub
    End If

    ' If trigger value is rising '
    If PopupEventTrigger.Value = 1 Then
        ' Change Display '
        ExecuteCommand ("Display Popup")
    End If
End Sub
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; Make sure there is no error &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">IsError</span><span style="color: #D4D4D4">(PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">) </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Exit Sub</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; If trigger value is rising &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; Change Display &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"><span style="color: #569CD6">End Sub</span></span>
<span class="line"></span></code></pre></div>



<h2 class="wp-block-heading" id="h-let-s-make-it-scalable">Let’s Make it Scalable</h2>



<p class="wp-block-paragraph">While this solution works great for changing to one specific display, it doesn’t work great at scale. Imagine, for a moment, having to repeat the process of creating a new numeric input and writing the Visual Basic subroutine for every display you want to change to. Needless to say, this proposition elicits feelings of dread.</p>



<p class="wp-block-paragraph">To avoid this monotonous task, we are going to discuss a couple possible architecture changes to support additional display changes.</p>



<h3 class="wp-block-heading" id="h-potential-architectures">Potential Architectures</h3>



<p class="wp-block-paragraph">There are, of course, more options than the two I will address here; however, they should generate some considerations for designing the architecture that fits best for your uses.</p>



<h3 class="wp-block-heading" id="h-custom-display-indexing">Custom Display Indexing</h3>



<p class="wp-block-paragraph">The numeric display we have been using to trigger our subroutine is not limited to a 1 or 0, so let’s make use of it. Change the expression to read an int on the PLC, and let&#8217;s move to a display based on what int is shown.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/integer-expression-in-numeric-display.png" alt="Integer Expression in Numeric Display"/></figure>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' Make sure there is no error '
    If IsError(PopupEventTrigger.Value) Then
        Exit Sub
    End If

    Select Case PopupEventTrigger.Value
        Case 1
            ExecuteCommand ("Display Popup1")
        Case 2
            ExecuteCommand ("Display Popup2")
        Case 3
            ExecuteCommand ("Display Popup3")
    End Select
End Sub
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; Make sure there is no error &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">IsError</span><span style="color: #D4D4D4">(PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">) </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Exit Sub</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">Select</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Case</span><span style="color: #D4D4D4"> PopupEventTrigger.Value</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Case</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">1</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup1&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Case</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">2</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup2&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Case</span><span style="color: #D4D4D4"> </span><span style="color: #B5CEA8">3</span></span>
<span class="line"><span style="color: #D4D4D4">            </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display Popup3&quot;</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End Select</span></span>
<span class="line"><span style="color: #569CD6">End Sub</span></span>
<span class="line"></span></code></pre></div>



<p class="wp-block-paragraph">This approach is handy as it allows you to map integer values to displays, similar to how the process works in ME. All the display changes are handled here in this subroutine; however, you will have to manually add each new display you want to transition to. To avoid this, we can have the PLC pass a string indicating a destination display.</p>



<h3 class="wp-block-heading" id="h-passing-strings-from-the-plc">Passing Strings from the PLC</h3>



<p class="wp-block-paragraph">By setting a string on the PLC for the HMI to read, we can indicate any display we want to transfer to! For simplicity, let&#8217;s create a string display on our <code>PopupHandler</code> screen to reference in our VBA. There, we can change our command to display whatever display is referenced in the string. Make sure that the string display has plenty of characters, as it will trim the PLCs string to the specified character amount. Additionally, make sure to expose the string display to VBA from the property panel with the option &#8220;VBA Control&#8221;.</p>



<figure class="wp-block-image"><img decoding="async" src="https://static.dmcinfo.com/wp-content/uploads/2025/05/addition-of-string-display-to-popuphandler.png" alt="Addition of String Display to PopupHandler"/></figure>



<div class="wp-block-kevinbatdorf-code-block-pro cbp-has-line-numbers" data-code-block-pro-font-family="Code-Pro-JetBrains-Mono" style="font-size:.875rem;font-family:Code-Pro-JetBrains-Mono,ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,monospace;--cbp-line-number-color:#D4D4D4;--cbp-line-number-width:calc(2 * 0.6 * .875rem);line-height:1.25rem;--cbp-tab-width:2;tab-size:var(--cbp-tab-width, 2)"><span style="display:flex;align-items:center;padding:16px 0 0 16px;width:100%;text-align:left;background-color:#1e1e1e"><span style="background:#c7c7c7;padding:0.3rem 0.5rem 0.2rem;border-radius:1rem;font-size:0.8em;line-height:1;height:1.25rem;text-align:center;display:inline-flex;align-items:center;justify-content:center;color:#1e1e1e">VB</span></span><span role="button" tabindex="0" style="color:#D4D4D4;display:none" aria-label="Copy" class="code-block-pro-copy-button"><pre class="code-block-pro-copy-button-pre" aria-hidden="true"><textarea class="code-block-pro-copy-button-textarea" tabindex="-1" aria-hidden="true" readonly>
Private Sub PopupEventTrigger_Change()
    ' Make sure there is no error '
    If IsError(PopupEventTrigger.Value) Then
        Exit Sub
    End If

    ' If trigger bit rising '
    If PopupEventTrigger.Value = 1 Then
        ' Trigger display change based on the value of the passed string '
        ExecuteCommand ("Display " &amp; DisplayNameString.Value)
    End If
End Sub
</textarea></pre><svg xmlns="http://www.w3.org/2000/svg" style="width:24px;height:24px" fill="none" viewBox="0 0 24 24" stroke="currentColor" stroke-width="2"><path class="with-check" stroke-linecap="round" stroke-linejoin="round" d="M4.5 12.75l6 6 9-13.5"></path><path class="without-check" stroke-linecap="round" stroke-linejoin="round" d="M16.5 8.25V6a2.25 2.25 0 00-2.25-2.25H6A2.25 2.25 0 003.75 6v8.25A2.25 2.25 0 006 16.5h2.25m8.25-8.25H18a2.25 2.25 0 012.25 2.25V18A2.25 2.25 0 0118 20.25h-7.5A2.25 2.25 0 018.25 18v-1.5m8.25-8.25h-6a2.25 2.25 0 00-2.25 2.25v6"></path></svg></span><pre class="shiki dark-plus" style="background-color: #1E1E1E" tabindex="0"><code><span class="line"></span>
<span class="line"><span style="color: #569CD6">Private Sub </span><span style="color: #DCDCAA">PopupEventTrigger_Change</span><span style="color: #D4D4D4">()</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; Make sure there is no error &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> </span><span style="color: #DCDCAA">IsError</span><span style="color: #D4D4D4">(PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">) </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #C586C0">Exit Sub</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #6A9955">&apos; If trigger bit rising &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">If</span><span style="color: #D4D4D4"> PopupEventTrigger.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4"> = </span><span style="color: #B5CEA8">1</span><span style="color: #D4D4D4"> </span><span style="color: #C586C0">Then</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #6A9955">&apos; Trigger display change based on the value of the passed string &apos;</span></span>
<span class="line"><span style="color: #D4D4D4">        </span><span style="color: #9CDCFE">ExecuteCommand</span><span style="color: #D4D4D4"> (</span><span style="color: #CE9178">&quot;Display &quot;</span><span style="color: #D4D4D4"> &amp; DisplayNameString.</span><span style="color: #9CDCFE">Value</span><span style="color: #D4D4D4">)</span></span>
<span class="line"><span style="color: #D4D4D4">    </span><span style="color: #C586C0">End If</span></span>
<span class="line"><span style="color: #569CD6">End Sub</span></span>
<span class="line"></span></code></pre></div>



<p class="wp-block-paragraph"><strong>If you want help with your FactoryTalk View SE project or <a href="https://static.dmcinfo.com/services/manufacturing-automation-and-intelligence/plc-programming">PLC development</a>, <a href="https://static.dmcinfo.com/contact">contact us</a>&nbsp;today for your next project&nbsp;</strong>—<strong>&nbsp;we would love to help!</strong></p>
<p>The post <a href="https://static.dmcinfo.com/blog/17267/triggering-popups-and-display-changes-in-factorytalk-view-site-edition-from-the-plc/">Triggering Popups and Display Changes in FactoryTalk View Site Edition from the PLC</a> appeared first on <a href="https://static.dmcinfo.com/">DMC, Inc.</a>.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
