<?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>XojoScript &#8211; Xojo Programming Blog</title>
	<atom:link href="https://blog.xojo.com/tag/xojoscript/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.xojo.com</link>
	<description>Blog about the Xojo programming language and IDE</description>
	<lastBuildDate>Tue, 11 Feb 2025 20:12:15 +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>Testing and Debugging Code Assistants</title>
		<link>https://blog.xojo.com/2025/02/12/testing-and-debugging-code-assistants/</link>
		
		<dc:creator><![CDATA[Geoff Perlman]]></dc:creator>
		<pubDate>Wed, 12 Feb 2025 16:00:00 +0000</pubDate>
				<category><![CDATA[Learning]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Code Assistants]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<category><![CDATA[XojoScript]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=14458</guid>

					<description><![CDATA[As Senior Engineer Paul Lefebvre wrote back in 2022, Xojo added the ability to create Code Assistants starting with Xojo 2022r1. Code Assistants are functions&#8230;]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large is-resized"><img fetchpriority="high" decoding="async" width="984" height="1024" src="https://blog.xojo.com/wp-content/uploads/2025/02/CleanShot-2025-02-05-at-13.12.17@2x-984x1024.png" alt="" class="wp-image-14459" style="width:318px;height:auto" srcset="https://blog.xojo.com/wp-content/uploads/2025/02/CleanShot-2025-02-05-at-13.12.17@2x-984x1024.png 984w, https://blog.xojo.com/wp-content/uploads/2025/02/CleanShot-2025-02-05-at-13.12.17@2x-288x300.png 288w, https://blog.xojo.com/wp-content/uploads/2025/02/CleanShot-2025-02-05-at-13.12.17@2x-768x799.png 768w, https://blog.xojo.com/wp-content/uploads/2025/02/CleanShot-2025-02-05-at-13.12.17@2x.png 1026w" sizes="(max-width: 984px) 100vw, 984px" /></figure>



<p>As Senior Engineer Paul Lefebvre <a href="https://blog.xojo.com/2022/04/05/using-the-new-user-code-assistants-feature/" target="_blank" rel="noreferrer noopener">wrote</a> back in 2022, Xojo added the ability to create Code Assistants starting with Xojo 2022r1. Code Assistants are functions that manipulate the code selected in the Code Editor to help with various code editing tasks. Code Assistants are written in <a href="https://documentation.xojo.com/api/language/xojoscript.html" target="_blank" rel="noreferrer noopener">XojoScript</a>, but XojoScript has no access to the Xojo Debugger. Fortunately, there&#8217;s a simple solution to this problem.</p>



<p>Xojo&#8217;s Code Assistant Tester example project makes it easy to test and debug your code before you create your Code Assistant. Go to File &gt; New Project, click on Examples then open the IDE folder to find it. With this example, you can enter the code that would go into your eventual XojoScript that will be your Code Assistant. Because this code is in methods in Xojo itself, you can test it and debug it with the Xojo Debugger.</p>



<p>Here&#8217;s a quick video on how to use Code Assistants and the Code Assistant Tester:</p>



<figure class="wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio"><div class="wp-block-embed__wrapper">
<iframe title="Introducing Xojo&#039;s New Code Assistants" width="500" height="281" src="https://www.youtube.com/embed/GDWQC1c6svQ?feature=oembed" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
</div></figure>



<p>If you write some handy Code Assistants, consider sharing them on the <a href="https://forum.xojo.com">Xojo Forum</a> they could be useful to others in the community.</p>



<p><em>Geoff Perlman is the Founder and CEO of Xojo. When he’s not leading the Xojo team he can be found playing drums in Austin, Texas and spending time with his family.</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>
		<item>
		<title>Using the New User Code Assistants Feature</title>
		<link>https://blog.xojo.com/2022/04/05/using-the-new-user-code-assistants-feature/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Tue, 05 Apr 2022 13:30:00 +0000</pubDate>
				<category><![CDATA[Cross-Platform]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Code Assistants]]></category>
		<category><![CDATA[Code Editor]]></category>
		<category><![CDATA[Rapid Application Development]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Xojo Programming Language]]></category>
		<category><![CDATA[XojoScript]]></category>
		<guid isPermaLink="false">https://blog.xojo.com/?p=10131</guid>

					<description><![CDATA[With Xojo 2022 Release 1, you can use XojoScript to create Code Assistants for use with selected text in the Code Editor. Here’s a quick example of one that swaps the prefix of a comment:]]></description>
										<content:encoded><![CDATA[
<p>With Xojo 2022 Release 1, you can use <a href="https://documentation.xojo.com/api/code_execution/xojoscript.html">XojoScript</a> to create <a href="https://documentation.xojo.com/getting_started/using_the_ide/code_editor.html#getting-started-using-the-ide-code-editor-code-assistants">Code Assistants</a> for use with selected text in the <a href="https://documentation.xojo.com/getting_started/using_the_ide/code_editor.html#">Code Editor</a>. Here’s a quick example of one that swaps the prefix of a comment:</p>



<pre class="wp-block-preformatted">// This script takes the current selected comment
// and changes the comment prefix.

Function Name() As String
  Return "Swap Comment Prefix"
End Function

Function CanEdit(selection As String) As Boolean
  // Check if comments starts with // or '.
  Return Left(selection, 2) = "//" Or Left(selection, 1) = "'"
End Function

Function Edit(selection As String) As String
  // Swap // with ' or swap ' with //
  If Left(selection, 1) = "'" Then
    Return Replace(selection, "'", "//")
  ElseIf Left(selection, 2) = "//" Then
    Return Replace(selection, "//", "'")
  End If
End Function</pre>



<p>This is not too lengthy, so let’s examine the parts. With a code assistant, there are three methods that are required: Name, CanEdit and Edit.</p>



<p>The <strong>Name()</strong> method returns a string containing the name that will appear in the Code Assistants menu. You can nest items using slashes, so “Paul/Swap Comments Prefix” would have this appear in Code Assistants-&gt;Paul-&gt;Swap Comments Prefix.</p>



<p>The <strong>CanEdit() </strong>method provides the code editor selection as a parameter. In this method you should return True if this code assistant is allowed to edit the selection. If you return True, the name will appear in the Code Assistants menu. If you return False it will not appear in the menu.</p>



<p>The code above checks if the selected text starts with the comment prefixes we want to swap: // or ‘.</p>



<p>The <strong>Edit()</strong> method is where you modify the selection, returning new text that will replace the selection in the Code Editor. This method does a single replace of “//“ with “’” and “’” with “//“.</p>



<p>Save the above script as SwapCommentPrefix.xojo_code_assistant and copy it to the Scripts folder in your IDE install folder.</p>



<p>If Xojo was running, you can tell it to reload those scripts by holding down Cmd (on Mac) or Control (Windows/Linux) when right-clicking.</p>



<p>Now type a comment like this:</p>



<pre class="wp-block-preformatted">‘ This is a comment.</pre>



<p>Select that comment and right-click. Choose Code Assistants-&gt;Swap Comment Prefix.</p>



<p>The line now shows as:</p>



<pre class="wp-block-preformatted">// This is a comment.</pre>



<p>For other sample Code Assistant scripts, go to Examples/Advanced/IDE Scripts/Code Assistants in the Xojo <a href="https://www.xojo.com/download/">download</a> folder.</p>



<p>Learn more in this <a href="https://youtu.be/GDWQC1c6svQ">video</a>! Be sure to share your Code Assistant scripts in the <a href="https://forum.xojo.com">forum</a>!</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Execute a Formula using XojoScript</title>
		<link>https://blog.xojo.com/2016/08/04/execute-a-formula-using-xojoscript/</link>
					<comments>https://blog.xojo.com/2016/08/04/execute-a-formula-using-xojoscript/#comments</comments>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 04 Aug 2016 09:00:20 +0000</pubDate>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[XojoScript]]></category>
		<guid isPermaLink="false">http://blog.xojo.com/?p=1500</guid>

					<description><![CDATA[On the Xojo forum a user asked if there was a way to execute a formula in Xojo. As pointed out in the conversation, Xojo includes&#8230;]]></description>
										<content:encoded><![CDATA[<p>On the <a href="https://forum.xojo.com/34304-execute-a-formula">Xojo forum a user asked if there was a way to execute a formula in Xojo</a>. As pointed out in the conversation, Xojo includes an Evaluator example that does exactly that. It uses <a href="http://developer.xojo.com/userguide/xojoscript">XojoScript</a> and I thought it might be interesting to show how it works.</p>
<p><span id="more-1500"></span>First, you can find the example by opening the Project Chooser (File-&gt;New), clicking “Examples” and then going to Advanced, XojoScript and selecting Evaluator.</p>
<p><img decoding="async" class="alignnone wp-image-1501" src="https://blog.xojo.com/wp-content/uploads/2016/08/2016-08-02_10-59-55.png" alt="ProjectChooser" width="300" height="166" /></p>
<p>Looking at the project you’ll see it has a primary Window (MainWindow) and a class called Evaluator. The Evaluator class is a subclass of XojoScript.</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1502" src="https://blog.xojo.com/wp-content/uploads/2016/08/2016-08-02_11-00-54.png" alt="EvaluatorProject" width="1290" height="701" /></p>
<p>The way this project works is that it takes the formula that was entered in the TextField of the window and embeds it into XojoScript source and then runs the source to get the result, which is returned back to the window to display.</p>
<p>Take a look at the Eval method on the Evaluator class. It’s primary code is this:</p>
<pre> Dim source As String
 
 source = "Dim expr As Variant = " + expression + EndOfLine + _
 "If expr.IsNumeric Then " + EndOfLine + _
 "mResult = Str(expr.DoubleValue)" + EndOfLine + _
 "Else " + EndOfLine + _
 "mResult = expr" +EndOfLine + _
 "End If"
 
 Self.Source = source
 Self.Context = Self // So we can refer to Evaulator.mResult property in XojoScript
 Self.Run
 
 Return mResult</pre>
<p>This code assigns the XojoScript source using the Source property and sets the Context property to itself which allows the XojoScript source to access the mResult property on the Evaluator class. Then it runs the XojoScript source.</p>
<p>This source assigns the formula to the line “Dim expr As Variant”, checks if the result is numeric and if it is, converts it to a string. The expression is then assigned to the mResult property so that it can be accessed outside the XojoScript source.</p>
<p>Which, back in the code for Eval, is what gets returned to the caller to display.</p>
<p>Of course, this does require that you pass in a valid Xojo expression that can be evaluated. Some example include:</p>
<ul>
<li>Hex(255), which returns FF</li>
<li>Left(“XojoScript, 4), which returns Xojo</li>
</ul>
<p>If you pass something that cannot be evaluated, you’ll get an error message which is displayed by either the CompilerError or RuntimeError events on the Evaluator class. Take a look at the ErrorCodeToString method to see a list of the possible errors. For example, the values below all generate an error:</p>
<ul>
<li>54 + “test” displays a “Type Mismatch” error.</li>
<li>“Dim i As Integer” displays a “Syntax does not make sense” error.</li>
<li>PMT(45) displays “Unidentified identifier”</li>
</ul>
<p>This sort of technique can be useful for projects where you want to dynamically run calculations that are not determined until the app is run.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.xojo.com/2016/08/04/execute-a-formula-using-xojoscript/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
			</item>
		<item>
		<title>Use IDE Scripting To Be More Efficient</title>
		<link>https://blog.xojo.com/2015/12/17/use-ide-scripting-to-be-more-efficient/</link>
		
		<dc:creator><![CDATA[Paul Lefebvre]]></dc:creator>
		<pubDate>Thu, 17 Dec 2015 00:00:00 +0000</pubDate>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Beginner Tips]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[IDE]]></category>
		<category><![CDATA[XojoScript]]></category>
		<guid isPermaLink="false">http://blogtemp.xojo.com/2015/12/17/use-ide-scripting-to-be-more-efficient/</guid>

					<description><![CDATA[Review your workflows to see if you can make improvements. IDE Scripts can help with that.]]></description>
										<content:encoded><![CDATA[<p>Did you know that you can create scripts to control the Xojo IDE? And many of these scripts could be real time savers.</p>
<p><span id="more-336"></span></p>
<p>As you roll into the new year, it can be a good time to review your workflows to see if you can make some improvements. Perhaps IDE Scripts can help with that.</p>
<p><img decoding="async" style="width: 320px; display: block; margin-left: auto; margin-right: auto;" title="WatercoolerPic.jpg" src="https://blog.xojo.com/wp-content/uploads/2015/12/WatercoolerPic.jpgt1466486449161ampwidth320" sizes="(max-width: 320px) 100vw, 320px" alt="WatercoolerPic.jpg" width="320" /></p>
<p>I was reminded of this by the wonderful &#8220;<a href="https://forum.xojo.com/14442-share-useful-ide-scripts">Share useful IDE scripts</a>&#8221; forum conversation (started by Jeremy Cowgar) that has some great script examples. Be sure to check it out. Some of the script examples include:</p>
<ul>
<li>Sort lines of code</li>
<li>Toggle Find Panel Display</li>
<li>Reload a Project</li>
<li>Find/Find Next</li>
<li>Project Diff</li>
<li>Markdown Preview</li>
<li>Obfuscate Code</li>
</ul>
<p>And don&#8217;t forget Jeremy&#8217;s wonderful Code Formatting IDE Script which is available on GitHub:</p>
<ul>
<li><a href="https://github.com/jcowgar/xojo-format-code">Xojo Format Code</a></li>
</ul>
<p>When you&#8217;re ready to create your own scripts, read the IDE Scripting docs in the Xojo Dev Center:</p>
<ul>
<li><a href="http://developer.xojo.com/ide-scripting">IDE Scripting</a></li>
<li><a href="http://developer.xojo.com/ide-scripting-commands">IDE Scripting Commands</a></li>
</ul>
<p>I&#8217;ve written about IDE Scripts before (<a href="../../../com/xojo/blog/build-all-the-things.html" target="_blank">Build All The Things</a> and <a href="/2013/12/17/ide_scripting/">IDE Scripts Included with Xojo</a>), so also be sure to review those scripts for examples and ideas.</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
