<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet type="text/xsl" href="RSS_xslt_style.asp" version="1.0" ?>
<rss version="2.0" xmlns:WebWizForums="https://syndication.webwiz.net/rss_namespace/">
 <channel>
  <title>Codejock Developer Community : Proper Validati&#111;n of xtpC&#111;ntrolEdit (VB6)</title>
  <link>http://forum.codejock.com/</link>
  <description><![CDATA[This is an XML content feed of; Codejock Developer Community : Command Bars : Proper Validati&#111;n of xtpC&#111;ntrolEdit (VB6)]]></description>
  <copyright>Copyright (c) 2006-2013 Web Wiz Forums - All Rights Reserved.</copyright>
  <pubDate>Sat, 16 May 2026 04:39:19 +0000</pubDate>
  <lastBuildDate>Sun, 07 May 2006 10:52:57 +0000</lastBuildDate>
  <docs>http://blogs.law.harvard.edu/tech/rss</docs>
  <generator>Web Wiz Forums 12.04</generator>
  <ttl>360</ttl>
  <WebWizForums:feedURL>forum.codejock.com/RSS_post_feed.asp?TID=2909</WebWizForums:feedURL>
  <image>
   <title><![CDATA[Codejock Developer Community]]></title>
   <url>http://forum.codejock.com/forum_images/codejock-logo.gif</url>
   <link>http://forum.codejock.com/</link>
  </image>
  <item>
   <title><![CDATA[Proper Validati&#111;n of xtpC&#111;ntrolEdit (VB6) : Excellent post - thanks Milkman,...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=2909&amp;PID=12728&amp;title=proper-validation-of-xtpcontroledit-vb6#12728</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=1446">apuhjee</a><br /><strong>Subject:</strong> 2909<br /><strong>Posted:</strong> 07 May 2006 at 10:52am<br /><br />Excellent post - thanks Milkman, you saved a few hairs on my head!<br /><br />Cheers ~ jp]]>
   </description>
   <pubDate>Sun, 07 May 2006 10:52:57 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=2909&amp;PID=12728&amp;title=proper-validation-of-xtpcontroledit-vb6#12728</guid>
  </item> 
  <item>
   <title><![CDATA[Proper Validati&#111;n of xtpC&#111;ntrolEdit (VB6) :          Most of my applications...]]></title>
   <link>http://forum.codejock.com/forum_posts.asp?TID=2909&amp;PID=8664&amp;title=proper-validation-of-xtpcontroledit-vb6#8664</link>
   <description>
    <![CDATA[<strong>Author:</strong> <a href="http://forum.codejock.com/member_profile.asp?PF=1488">Milkman</a><br /><strong>Subject:</strong> 2909<br /><strong>Posted:</strong> 16 September 2005 at 11:06pm<br /><br /><span style="color: rgb(0, 0, 0);">Most of my applications require that any text entered into an edit boxbe checked for consistency.&nbsp; For instance, if the user enters xyzin an ID# edit box, you wouldn't want your program to use a lettervalue when it should use a number value.&nbsp; The typical desiredresult would be to discard the incorrectly entered value and restorethe previous contents of the edit box.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Unfortunately, the method in which to do this isn't exactly spelled outin the substandard documentation.&nbsp; Adding insult to injury, thereisn't even an editbox worked into ANY of the command bar samples.&nbsp;Below is the required code to implement proper validation of anxtpControlEdit within a command bar.&nbsp; It uses the Tag (they callit the "Paramater") property of the edit control to store the previouscontents of the edit box.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">You'll first need to create an ID number for the editbox.&nbsp; Createthis global value in a seperate module where you store your constants.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><table width="99%"><tr><td><pre class="BBcode"></span><span style="color: rgb(0, 0, 0);">Public Const ID_EDIT = 205</pre></td></tr></table></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">You then need to construct your command bar.</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><table width="99%"><tr><td><pre class="BBcode"></span><span style="color: rgb(0, 0, 0);">Private Sub cbToolbar()</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Declare Temporary Variables</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Dim Control As CommandBarControl</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Dim Toolbar As CommandBar</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Dim EditControl As CommandBarEdit</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Set Toolbar properties</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Set Toolbar = CommandBars.Add("Test Command Bar", xtpBarBottom)</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Create Toolbar</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">With Toolbar.Controls</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp; Set EditControl = .Add(xtpControlEdit, ID_EDIT, "")</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EditControl.Text = "Test"</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; EditControl.Parameter = EditControl.Text</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">End With<br></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">End Sub<br></pre></td></tr></table><br><br>After the control exists you'll needto put some additional code in the "ControlSelected" (catchs when youpress the Enter key) and "Update" (catch the case where you change thetext and then just leave the text box without pressing the enter key)Events.<br><br><table width="99%"><tr><td><pre class="BBcode">Private Sub CommandBars_ControlSelected(ByVal Control As XtremeCommandBars.ICommandBarControl)<br><br>'Process Selected Events<br>If Control Is Nothing Then Exit Sub<br>Select Case Control.Id<br>&nbsp;&nbsp;&nbsp; Case ID_EDIT:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Control.Parameter &lt;&gt; Control.Text Then EditBox_Validate Control<br>End Select<br><br>End Sub<br></pre></td></tr></table><br><br><table width="99%"><tr><td><pre class="BBcode">Private Sub CommandBars_Update(ByVal Control As XtremeCommandBars.ICommandBarControl)</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Process Update Requests</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">If Control Is Nothing Then Exit Sub</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Select Case Control.Id</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp; Case ID_EDIT:</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;If (Control.HasFocus = False) And (Control.Text &lt;&gt;Control.Parameter) Then EditBox_Validate Control</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">End Select</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">End Sub</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></pre></td></tr></table></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">You're probably wondering why the "If Control Is Nothing Then Exit Sub"line at the beginning of each event handler.&nbsp; Well it would appearthat these event handlers are sometimes called without a controlvariable passed to it.&nbsp; Very strange.&nbsp; The example programschoose to use the "On Error Resume Next" command to juse ignore anyerrors.&nbsp; I don't like this approach because it turns off errorchecking for the rest of the code in the event handler.&nbsp; A badthing when you're trying to debug your program.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Finally you'll need to add the validation routine.&nbsp; Use something like this.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"><table width="99%"><tr><td><pre class="BBcode"></span><span style="color: rgb(0, 0, 0);">Private Sub EditBox_Validate(ByRef EditBox As CommandBarEdit)</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'This sub will validate the edit box text</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Check the text in the EditBox.Text property</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'If bad then replace replace .Text with .Parameter</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Maybe you want to raise an error</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'If text is good then let it be and update the .Parameter for the next time the </span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'validate routine is called</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">'Validation Successful</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">EditBox.Parameter = EditBox.Text</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">End Sub</span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></pre></td></tr></table></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);"></span><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">If you want your program to programmatically update the text in theeditbox; make sure to change BOTH the .Text and the .Parameterproperties to avoid having the validate routine execute needlessly.</span><br style="color: rgb(0, 0, 0);"><br style="color: rgb(0, 0, 0);"><span style="color: rgb(0, 0, 0);">Now if I can only figure out how to centre text in the thing, I'll be set.</span><br style="color: rgb(0, 0, 0);"><br><br><br><span style="font-size:10px"><br /><br />Edited by Milkman</span>]]>
   </description>
   <pubDate>Fri, 16 Sep 2005 23:06:14 +0000</pubDate>
   <guid isPermaLink="true">http://forum.codejock.com/forum_posts.asp?TID=2909&amp;PID=8664&amp;title=proper-validation-of-xtpcontroledit-vb6#8664</guid>
  </item> 
 </channel>
</rss>