<?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>Index out of Bounds &#187; visual basic</title>
	<atom:link href="http://www.jonathanfritz.ca/tag/visual-basic/feed" rel="self" type="application/rss+xml" />
	<link>http://www.jonathanfritz.ca</link>
	<description>the personal portfolio of Jonathan Fritz</description>
	<lastBuildDate>Mon, 12 Dec 2011 03:22:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Automating Command Line Applications VisualBasic.Net</title>
		<link>http://www.jonathanfritz.ca/software/automating-command-line-applications-in-visualbasic-dot-net</link>
		<comments>http://www.jonathanfritz.ca/software/automating-command-line-applications-in-visualbasic-dot-net#comments</comments>
		<pubDate>Thu, 30 Apr 2009 01:47:00 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[batch script]]></category>
		<category><![CDATA[download]]></category>
		<category><![CDATA[exit code]]></category>
		<category><![CDATA[ftp]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[processstartinfo]]></category>
		<category><![CDATA[redirect standard output]]></category>
		<category><![CDATA[sftp]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[standard output]]></category>
		<category><![CDATA[system.diagnostics.process]]></category>
		<category><![CDATA[system.diagnostics.processstartinfo]]></category>
		<category><![CDATA[system.io.streamreader]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[winscp]]></category>

		<guid isPermaLink="false">http://jonathanfritz.ca/?p=98</guid>
		<description><![CDATA[A tutorial describing how to control command line operations in a more powerful manner than the shell function with the process class in visual studio.net. Includes source code for download.]]></description>
			<content:encoded><![CDATA[<p>A lot of the programming that I do for myself involves the creation of little tools that patch two existing parts of my workspace together so that they work better. For example, I recently had need of an SFTP client that links into a database front end to retrieve a list of files to download. Since the SFTP specification is ridiculously long and convoluted, I decided to try and use <a href="http://winscp.net/eng/index.php" target="_blank">WinSCP</a> to take care of the FTP portion of the program instead of re-inventing the wheel. Because I was trying to patch the database layer and FTP client together into a single application, I decided to take a shot at controlling WinSCP directly from the command line so that the two portions of the project were contained in a single application.</p>
<p>Readers who have spent time fooling around in Visual Basic 6 might remember the <a href="http://msdn.microsoft.com/en-us/library/xe736fyk(vs.71).aspx" target="_blank">Shell function</a> that allows a program to launch another process. Generally speaking, if we don&#8217;t care about the output of the program, or are just launching something like a browser window, this command is more than sufficient. However in this case, I wanted to capture the output of WinSCP and its exit code so that I could tell if errors had occurred and take appropriate action on them, so I needed something with a little bit more kick.</p>
<p>Since I wrote my code with WinSCP in mind, the rest of the article is going to focus on creating an application that will serve as an FTP front-end that allows the user to upload or download a file to or from a remote SFTP server. That said, the ideas are general and easy to adapt to any other application that supports command-line arguments.</p>
<p>You&#8217;ll want to begin by dragging and dropping the executable that you wish to automate directly into your project, and setting its &#8220;Copy to Output&#8221; property to &#8220;Copy to Newer&#8221; to ensure that your application can always find it. For WinSCP, that included both the winscp.com and winscp.exe files from the install directory. That done, let&#8217;s jump in.</p>
<h2>Using System.Diagnostics.Process:</h2>
<p>This handy System class provides a beefier version of the Shell functionality, and is really very easy to use, once you get the hang of it. At the top of your class, add the line <code>imports <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.aspx" target="_blank">System.Diagnostics</a></code> so that we can find the pieces that we&#8217;ll need with ease.</p>
<p>When automating a command-line application, we first create a <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.aspx" target="_blank">ProcessStartInfo</a> object that contains all of the information about the process that we would like to create. Start by declaring one of these:</p>
<p><code>Dim startInfo As New ProcessStartInfo("winscp.com")</code></p>
<p>This line creates a ProcessStartInfo object with the path to the application that we&#8217;d like to automate as it&#8217;s only argument. Next, we set a few properties of the object:</p>
<p><code>startInfo.Arguments = commandLineArguments</code><br />
<code>startInfo.UseShellExecute = False</code><br />
<code>startInfo.RedirectStandardOutput = True</code><br />
<code>startInfo.CreateNoWindow = True</code></p>
<p>The first line passes the string <code>commandLineArguments</code> to startInfo, telling it to give them to winscp.com as command line arguments. Command line argument options for most programs can be found on their websites. If you&#8217;re interested in WinSCP in particular, it has some great <a href="http://winscp.net/eng/docs/scripting" target="_blank">online documentation</a> that you can take a look at. The next three lines tell the startInfo object that it should direct the standard output from the process to a <a href="http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx" target="_blank"><code>System.IO.StreamReader</code></a> object where we can intercept it, and that it should run that process in the background, without showing the window to the user.</p>
<p>Next, we create a new <a href="http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx" target="_blank">Process</a> object, and pass it the information that we just stored in startInfo:</p>
<p><code>Dim p as New Process</code><br />
<code>p = Process.Start(startInfo)</code></p>
<p>This creates a new process for winscp.com, and passes it the command line arguments that we stored earlier in startInfo. Now, we need to catch the standard output from our newly created process and store it somewhere so that our users can see what the application did.</p>
<p><code>Dim s as IO.StreamReader = p.StandardOutput</code><br />
<code>While p.Responding</code><br />
<code style="padding-left: 30px;">Try</code><br />
<code style="padding-left: 60px;">lstOutput.Items.Add(s.ReadLine)</code><br />
<code style="padding-left: 30px;">Catch</code><br />
<code style="padding-left: 60px;">Exit While</code><br />
<code style="padding-left: 30px;">End Try</code><br />
<code>End While</code></p>
<p>On the first line, we create a new <code>IO.StreamReader</code> object that will catch the standard output from our hosted process. The while loop tries repeatedly to read a line of output from the application and dump it into a list box while the process is still responding to the operating system. When the application finishes its work, <code>s.ReadLine</code> will return null, killing the loop and allowing the program to continue.</p>
<p>Finally, when a program exits, it returns an exit code that lets the operating system know whether or not it completed its work successfully. We can access this code with the line</p>
<p><code>p.ExitCode</code></p>
<p>In most programs, if this returns zero, the program finished successfully. If an error was encountered, this function should return something other than zero, and depending on the program, the other value may have some meaning that you can use as a status check.</p>
<h2>Next Steps:</h2>
<p>Because this code is purposely general, it should be easy to adapt it to control most any application that provides some kind of command line interface. This method can make for a nice alternative to batch scripts if you need to write batch scripts with some kind of logic in them and don&#8217;t feel like installing a python interpreter to get the job done. At the cost of making the code application-specific, you could easily change it to analyze the output from the program and take some action based on those return values.</p>
<h2>Downloads:</h2>
<p>As always, the source is available for download. Check out Tyler Burton&#8217;s <a href="http://www.tylerburton.ca/2009/09/hash-verifier/" target="_blank">Hash Verifier</a> application if you want to ensure that you&#8217;re getting the same copy of the code that I claim you are.<br />
<strong>Source Code: </strong><a href="http://www.jonathanfritz.ca/files/ftp-process-control-source.zip" target="_self">Click Here</a><br />
<strong>MD5 Hash: </strong>4B5D543E193CAC2B4B9477727E17EFB2<br />
<strong>SHA1 Hash:</strong> ABD8692CBB20D316DBF35FE650399D034DA57697</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanfritz.ca/software/automating-command-line-applications-in-visualbasic-dot-net/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>OpenGL in VisualStudio.Net with the TAO Framework</title>
		<link>http://www.jonathanfritz.ca/software/opengl-in-visualstudionet-with-the-tao-framework</link>
		<comments>http://www.jonathanfritz.ca/software/opengl-in-visualstudionet-with-the-tao-framework#comments</comments>
		<pubDate>Wed, 04 Mar 2009 23:06:31 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[3d game engine]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[freeware]]></category>
		<category><![CDATA[games]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[rpg]]></category>
		<category><![CDATA[tao framework]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[xna]]></category>

		<guid isPermaLink="false">http://jonathanfritz.ca/?p=56</guid>
		<description><![CDATA[Some who read me on a regular basis might be wondering what ever happened to the RPG I was writing in VisualStudio using Microsoft&#8217;s XNA technology. Truth is, it never went anywhere. Like a lot of past projects, I got very psyched about it, wrote a bunch of code, and then school started and I [...]]]></description>
			<content:encoded><![CDATA[<p>Some who read me on a regular basis might be wondering what ever happened to the <a href="http://www.jonathanfritz.ca/software/troubles-with-xna" target="_blank">RPG I was writing</a> in VisualStudio using Microsoft&#8217;s XNA technology. Truth is, it never went anywhere. Like a lot of past projects, I got very psyched about it, wrote a bunch of code, and then school started and I got way too busy to finish it. I haven&#8217;t touched the code since I wrote that post, but now I&#8217;ve got some new ideas.</p>
<p>Last term in school, I took an excellent course on OpenGL programming with C++. The course covered how to create and render 3D graphics, with study lent to topics such as window management, points, vertices, and polygons, lighting and shading, hidden surface removal, and texturing. My earlier post about the <a href="http://www.jonathanfritz.ca/software/max-a-half-baked-3d-engine" target="_blank">MAX 3D Engine</a> was a byproduct of that course.</p>
<p>Since then, I&#8217;ve discovered a managed .NET wrapper around the OpenGL libraries called the <a href="http://www.taoframework.com/" target="_blank">Tao Framework</a> that allows you to (in theory) code any graphics application in Visual Basic or C# that you could in C++, with the added bonus of the pretty IDE, code completion, top of the line window handling procedures, and the .NET libraries. Now at this point, if you&#8217;re a graphics programmer, you&#8217;re laughing aloud at my outrageous claim &#8211; managed, run-time interpreted code could never be fast enough to run a video game! You may be correct. Frankly, I have no idea, as I haven&#8217;t yet had the time to write a full video game.</p>
<p>What I have come up with however, are two starter projects for anybody wishing to try their hand at OpenGL programming using Tao and Visual Basic.NET. The code in both is well documented, easy to follow (especially if you are familiar with standard OpenGL routines), and seems to run at a reasonable 60fps. Now, I can&#8217;t tell until I add a few more polygons to the scene whether this framerate is an artificial limit applied by the environment, or if interpreted code actually has no hope of ever running a game at a reasonable speed. That is an experiment for a later day. For now, I will simply share these starter projects for all to use. If you do something with them, please leave a comment and let me know how it went.</p>
<h2>Tao2D Test Harness:</h2>
<p>A simple application that spins a tri-coloured, smooth-shaded triangle around the y-axis.</p>
<p><strong>Source Code:</strong> <a href="http://www.jonathanfritz.ca/files/Tao%20Projects/Tao2D%20Source%20VB.Net.zip" target="_self">Tao2D Source VB.Net.zip</a></p>
<p><strong>MD5 Hash:</strong> 4DA0FC584B1EF8738B3B9CA4C1F55388</p>
<p><strong>Binaries:</strong> <a href="http://www.jonathanfritz.ca/files/Tao%20Projects/Tao2D%20Binary.zip" target="_self">Tao2D Binary.zip</a></p>
<p><strong>MD5 Hash:</strong> 611382CB00CADD860A81A85573CBA763</p>
<h2>Tao3D Test Harness:</h2>
<p>A simple application that spins a really crappy looking cone around the x-axis</p>
<p><strong>Source Code:</strong> <a href="http://www.jonathanfritz.ca/files/Tao%20Projects/Tao3D%20Source%20VB.NET.zip" target="_self">Tao3D Source VB.NET.zip</a></p>
<p><strong>MD5 Hash:</strong> 8D54DB42109F12C745AD14922FF8850E</p>
<p><strong>Binaries:</strong> <a href="http://www.jonathanfritz.ca/files/Tao%20Projects/Tao3D%20Binaries.zip" target="_self">Tao3D Binaries.zip</a></p>
<p><strong>MD5 Hash:</strong> 5D4CD4D02B3EE1194758A543DF36C034</p>
<p>As always, I recommend using <a href="http://www.tylerburton.ca/2009/09/hash-verifier/" target="_blank">Tyler Burton&#8217;s Hash Verifier</a> program to verify the integrity of these downloads.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanfritz.ca/software/opengl-in-visualstudionet-with-the-tao-framework/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Post-Midterms Class Roundup</title>
		<link>http://www.jonathanfritz.ca/software/post-midterms-class-roundup</link>
		<comments>http://www.jonathanfritz.ca/software/post-midterms-class-roundup#comments</comments>
		<pubDate>Sat, 01 Nov 2008 16:11:31 +0000</pubDate>
		<dc:creator>Jon</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[blackberry]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Copyright]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[free software]]></category>
		<category><![CDATA[itunes]]></category>
		<category><![CDATA[opengl]]></category>
		<category><![CDATA[playlist]]></category>
		<category><![CDATA[school]]></category>
		<category><![CDATA[visual basic]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://jonathanfritz.ca/?p=27</guid>
		<description><![CDATA[So midterms are finished, and life goes on. As much as I&#8217;d love this post to be tech-oriented, showcasing some brilliant new software that I&#8217;ve written in my spare time, the truth is, I haven&#8217;t had enough spare time lately in which to write any software of value. The small exception to that claim is [...]]]></description>
			<content:encoded><![CDATA[<p>So midterms are finished, and life goes on. As much as I&#8217;d love this post to be tech-oriented, showcasing some brilliant new software that I&#8217;ve written in my spare time, the truth is, I haven&#8217;t had enough spare time lately in which to write any software of value.</p>
<p>The small exception to that claim is <a href="http://www.jonathanfritz.ca/files/Blackberry%20Loader.zip" target="_self">this app</a>, a neat little VB and XML oriented program that allows you to read an iTunes playlist file (as exported to XML), and auto-copy all of the songs in that playlist to any folder you wish, preserving the artist/album/song file structure.</p>
<p>I wrote the program to fill my brand new blackberry with a selection of excellent songs, because the built in Roxio media manager is great for pictures, but slow as sin when it comes to larger media files. After writing it, I realized that it could also be a useful piracy tool; but then again, a hammer could be a positively fantastic homicide tool in the wrong hands too. Of all the libraries I&#8217;ve ever written, my .NET XML parser has spawned off more crappy little programs, making it possibly the most useful bit of code I&#8217;ve created.</p>
<p>Other than that, my coding has lately been limited to some cool graphics stuff in with OpenGL and C++. So far we&#8217;ve constructed a classic spinning cube implementation, complete with a custom view pipeline that implements transformations, dynamic shading, and back face culling in software. The next topic that we&#8217;re studying is texturing, and eventually, ray tracing and shaders.</p>
<p>While none of my assignments for this course have been interesting enough to warrant posting, I&#8217;ll definetly up my final project for the course, which at this point, is probably going to be a 3D terrain generator, similar to that of Sim City 4 fame.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jonathanfritz.ca/software/post-midterms-class-roundup/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

