<?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>GimmeSoda &#187; ASP.net</title>
	<atom:link href="http://www.gimmesoda.com/category/programming/asp-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gimmesoda.com</link>
	<description>The Blog of a Programmer</description>
	<lastBuildDate>Sun, 29 Jan 2012 10:26:09 +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>Visual Basic.net Console Applications</title>
		<link>http://www.gimmesoda.com/visual-basicnet-console-applications/</link>
		<comments>http://www.gimmesoda.com/visual-basicnet-console-applications/#comments</comments>
		<pubDate>Tue, 11 Jul 2006 18:03:00 +0000</pubDate>
		<dc:creator>JuanJose</dc:creator>
				<category><![CDATA[ASP.net]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.gimmesoda.com/?p=6</guid>
		<description><![CDATA[Microsoft Adds Improved Support for Console Apps in .Net
When I learned that .net had improved support for console apps I became immediately excited about the whole thing. I love data processing, parsing, and conversion; I&#8217;m a geek in all every possible sense of the word. It can be a true mental  [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-weight: bold">Microsoft Adds Improved Support for Console Apps in .Net</span></p>
<p>When I learned that .net had improved support for console apps I became immediately excited about the whole thing. I love data processing, parsing, and conversion; I&#8217;m a geek in all every possible sense of the word. It can be a true mental challenge to convert something one company believes to be a complete and sensible data format to what another company believes to be the same.</p>
<p>In this past week I came across the need to build a program which will be capable of automation and quickly converting one companies file format to another.</p>
<p><span style="font-weight: bold">O&#8217; The Possibilities</span></p>
<p>Since I am mostly a web based developer my immediate thought was VBScript (Classic ASP) hosted on an IIS capable server on which we would have a batch calling ftp to download the files which needed to be parsed, saving them to a specific folder, and executing the .asp script.</p>
<p>Unfortunately the server which would be running the program (decided on by the client company) does not run IIS, so there goes that idea. Another idea was to run it as a .vbs script using windows internal scripting. I&#8217;ve always had a bad feeling about using those files and decided that would not be a grand idea. Out of a gut feeling I scratched that idea.</p>
<p><span style="font-weight: bold">What about .net?</span></p>
<p>I had worked with VB.net only a few times before and thought it would be easy enough to do the job with. What about automation? Having a form without need of human intervention would allow the program to run by itself BUT why do I even need that? It would make the program larger and that is completely unnecessary. The next thought that came to my mind was, &#8220;I miss DOS.&#8221;</p>
<p><span style="font-weight: bold">DOS and Console Applications!</span></p>
<p>Most of you past the age of 20 or so should remember console apps. Those DOS console windows, the constant use of &#8220;cmd&#8221; or &#8220;command&#8221; from your start &#8212;&gt; run menu, and (for those of us who like to play those old dos games) <a href="http://www.freedos.org/">free dos</a> or <a href="http://dosbox.sourceforge.net/news.php?show_news=1">DOSBox</a>! Either way, those wonderful apps didn&#8217;t just become useless or out of style with the advent of easily built apps with nifty GUI&#8217;s!</p>
<p>Console apps are great for processing and well automating processes! Which is how I am using my newest little application.</p>
<p><span style="font-weight: bold">How to Write Console Apps with .Net 2003</span><span style="font-weight: bold"><span style="font-weight: bold"></span>Okay first off, I know .net 2005 is out. I&#8217;m currently using .net visual studio 2003, and although the process should be similar in 2005, perhaps even better; I&#8217;m using 2003 and that&#8217;s what you&#8217;ll learn here. That is, until I get upgraded.</span><span style="font-weight: bold">So open up your .net enviroment.</p>
<p></span>Create a new project selecting Visual Basic Projects (left hand side), and Console Application (right hand side). Name your application and have it save to whatever location you&#8217;d like.</p>
<p><span style="font-weight: bold"><span style="font-weight: bold"></span>Module1.vb</span><span style="font-weight: bold">If you are anything like me you&#8217;ll love the fact that the first thing you see after creating this new application is a code window! None of the GUI or form clutter. Straight to the heart of the matter! Now unless your application is completely static, as in it always processes the same file(s), you&#8217;ll need your program to handle arguments. In my case it needs to handle 1 argument and that would be the file name of the text file to be parsed.</span><span style="font-weight: bold"><span style="font-weight: bold">Handling Arguments<br />
</span></p>
<p></span></p>
<blockquote><p>Sub Main()<br />
Main(System.Environment.GetCommandLineArgs())<br />
End Sub</p></blockquote>
<p>Wonderful little piece of code! Since this is the first function executed in your program all it will do is collect the arguments from the command line and pass them into a private sub also called Main in your application, in which you can check for the correct arguments and actually do your processing! Here is a basic example:</p>
<blockquote><p>Private Sub Main(ByVal arguments() As String)<br />
If arguments Is Nothing OrElse arguments.Length &lt;&gt; 2 Then<br />
Console.WriteLine(&#8220;You must enter atleast one argument for this program to execute!&#8221;)<br />
Else<br />
System.Console.WriteLine(&#8220;&#8211;==Welcome to My Console Application==&#8211;&#8221;)<br />
If (arguments(1) = &#8220;-V&#8221;) Then<br />
System.Console.WriteLine(&#8220;&#8211;==Written by JuanJose H. Galvez==&#8211;&#8221;)<br />
Exit Sub<br />
Else<br />
Dim user_name<br />
System.Console.WriteLine(&#8220;What is your name?&#8221;)<br />
user_name = System.Console.ReadLine()<br />
System.Console.WriteLine(&#8220;Your name is: &#8221; &amp; user_name)<br />
End If<br />
End If<br />
End Sub</p></blockquote>
<p>From the above example you should be able to figure out how to initiate variables, set user input into a program usable variable, how to write out strings to the screen! Also, you&#8217;ll either run into this or figure it out yourself but arguments(0) is actually equal to the filename of the program, which is why the argument(1) is used when seeking the input argument used to run the program.</p>
<p>Example: &#8220;ConsoleApplication1.exe&#8221; -V<br />
Example: &#8220;ConsoleApplication1.exe&#8221; AnythingCanGoHere</p>
<p><span style="font-weight: bold">This is obviously a useless program!<br />
You&#8217;ve wasted my time!</span><span style="font-weight: bold">Actually, this little program was indeed a useless example, in that it does nothing of use; thus the use of the term useless; but it does end up teaching someone who is new to console applications how to get started. It also teaches the basic concepts behind arguments and how to do basic input output operations between the program and the end user.</span><span style="font-weight: bold">And you wasted your own time reading this! I wasted time writing! :)<br />
<span style="font-weight: bold"></span></p>
<p></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.gimmesoda.com/visual-basicnet-console-applications/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: www.gimmesoda.com @ 2012-02-10 08:51:59 -->
