<?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>API Programming &#187; VB.NET</title>
	<atom:link href="http://www.brangle.com/wordpress/category/tutorials/vb-net-tutorials/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.brangle.com/wordpress</link>
	<description>Just another computer weblog</description>
	<lastBuildDate>Wed, 14 Dec 2011 07:35:21 +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>How To Use the OpenFileDialog Box in VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/09/howto-use-the-openfiledialog-box-in-vbnet/</link>
		<comments>http://www.brangle.com/wordpress/2009/09/howto-use-the-openfiledialog-box-in-vbnet/#comments</comments>
		<pubDate>Tue, 08 Sep 2009 05:40:42 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=588</guid>
		<description><![CDATA[Using the OpenFileDialog box wasn't as intuitive as I initially expected, I was thinking I could just drag it out onto my form as a button and place it right where I wanted to. But when I clicked on it from toolbox it just went into the bottom frame of my application, but not on my form like I was hoping for. Below I is an example of a dynamically (aka created at run) created OpenFileDialog. Because it's dynamically created when don't have to drag it out to form, it's created by the code, not from the GUI. [...]]]></description>
			<content:encoded><![CDATA[<p>Using the OpenFileDialog box wasn&#8217;t as intuitive as I initially expected, I was thinking I could just drag it out onto my form as a button and place it right where I wanted to.  But when I clicked on it from toolbox it just went into the bottom frame of my application, but not on my form like I was hoping for.  Below I is an example of a dynamically (aka created at run) created OpenFileDialog.  Because it&#8217;s dynamically created when don&#8217;t have to drag it out to  form, it&#8217;s created by the code, not from the GUI.<span id="more-588"></span></p>
<p>In this example, I put the OpenFileDialog in a function and not a subroutine.  The reason for this is that I want to return a value.  Functions allow you to return a value whereas a subroutine does not.</p>
<p>Let&#8217;s take a look at this screen shot, there are 3 main elements that we can set which I&#8217;ll describe in further detail.  They are the initial directory, filter, and filter index.</p>
<div id="attachment_594" class="wp-caption aligncenter" style="width: 576px"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/09/OpenFileDialog.jpg" alt="OpenFileDialog" title="OpenFileDialog" width="566" height="483" class="size-full wp-image-594" /><p class="wp-caption-text">OpenFileDialog</p></div>
<p><b>Initial Directory</b> &#8211; I guess the easiest one to explain in the initial directory, when you open the dialog box you&#8217;ll typically want it to open to a particular folder, in most cases I would guess this to be the user&#8217;s <i>My Documents</i> folder.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">fileDialogBox.<span style="color: #0000FF;">InitialDirectory</span> <span style="color: #008000;">=</span> Environment.<span style="color: #0000FF;">GetFolderPath</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">SpecialFolder</span>.<span style="color: #0000FF;">Personal</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>The above line does just that, we query the .NET class Environment to get the locations of the users My Documents folder. But now what if we wanted it to open up in the <i>C:\Program Files</i> folder? Simple enough&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">fileDialogBox.<span style="color: #0000FF;">InitialDirectory</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;C:\Program Files&quot;</span></pre></div></div>

<p><b>Filter</b> &#8211; This allows us to filter the filetypes/filenames that we want to see in the OpenFileDialog.  For example, if I want to only see *.txt I can create a text filter by assigning <i>fileDialogBox.Filter = Text Files (*.txt)|*.txt|</i> and literally we just repeat this pattern to add more file types.  Here&#8217;s a few more examples.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;">fileDialogBox.<span style="color: #0600FF;">Filter</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Text Files (*.txt)|*.text|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;Word Documents (*.doc;*.docx)|*.doc;*.docx|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;boot.ini (boot.ini)|boot.ini|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;All text files beginning with the letter A (a*.txt)|a*.txt|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;All files beginning with accesslog* (accesslog*)|accesslog*|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;All Files(*.*)|&quot;</span></pre></td></tr></table></div>

<p><b>Filter Index</b> &#8211; To default to a particular filter you will need to select a filter index.  In this example you&#8217;ll notice that I have boot.ini selected.  We can do that by looking at the above piece of code and noticing that boot.ini comes 3rd in that list.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">fileDialogBox.<span style="color: #0000FF;">FilterIndex</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span></pre></div></div>

<p>That&#8217;s it, this allows us to keep our filters arranged alphabetically and still be able to select an item from the middle of the list.</p>
<p><b>The Code</b> &#8211; Here it is.  In the function <i>OpenFile()</i> it will return a string with the filename and path as a string.  If no filename is selected, a blank string is returned.  In the subroutine <i>btnOpenFile_Click</i> if we do have a file then I&#8217;ll just retrieve some of the file info and display it on a message box otherwise I&#8217;ll tell the user that they did not select a file.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/09/howto-use-the-openfiledialog-box-in-vbnet/</span>
&nbsp;
<span style="color: #008080; font-style: italic;">'This was declared as a function because I want to be able to return a filename</span>
<span style="color: #008080; font-style: italic;">'the filename will be returned as a string</span>
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Function</span> OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span>
	<span style="color: #008080; font-style: italic;">'declare a string, this is will contain the filename that we return</span>
	<span style="color: #0600FF;">Dim</span> strFileName <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span>
	<span style="color: #008080; font-style: italic;">'declare a new open file dialog</span>
	<span style="color: #0600FF;">Dim</span> fileDialogBox <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">New</span> OpenFileDialog<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'add file filters, this step is optional, but if you notice the screenshot</span>
	<span style="color: #008080; font-style: italic;">'above it does not look clean if you leave it off, I explained in further</span>
	<span style="color: #008080; font-style: italic;">'detail on my site how to add/modify these values</span>
	fileDialogBox.<span style="color: #0600FF;">Filter</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;Rich Text Format (*.rtf)|*.rtf|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;Text Files (*.txt)|*.txt|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;Word Documents (*.doc;*.docx)|*.doc;*.docx|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;Image Files (*.bmp;*.jpg;*.gif)|*.bmp;*.jpg;*.gif|&quot;</span> _
	    <span style="color: #008000;">&amp;</span> <span style="color: #808080;">&quot;All Files(*.*)|&quot;</span>
	<span style="color: #008080; font-style: italic;">'this sets the default filter that we created in the line above, if you don't </span>
	<span style="color: #008080; font-style: italic;">'set a FilterIndex it will automatically default to 1</span>
	fileDialogBox.<span style="color: #0000FF;">FilterIndex</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">3</span>
	<span style="color: #008080; font-style: italic;">'this line tells the file dialog box what folder it should start off in first</span>
	<span style="color: #008080; font-style: italic;">'I selected the users my document folder</span>
	fileDialogBox.<span style="color: #0000FF;">InitialDirectory</span> <span style="color: #008000;">=</span> Environment.<span style="color: #0000FF;">GetFolderPath</span><span style="color: #000000;">&#40;</span>Environment.<span style="color: #0000FF;">SpecialFolder</span>.<span style="color: #0000FF;">Personal</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'Check to see if the user clicked the open button</span>
	<span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>fileDialogBox.<span style="color: #0000FF;">ShowDialog</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> DialogResult.<span style="color: #0600FF;">OK</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
	    strFileName <span style="color: #008000;">=</span> fileDialogBox.<span style="color: #0000FF;">FileName</span>
	<span style="color: #008080; font-style: italic;">'Else</span>
	<span style="color: #008080; font-style: italic;">'   MsgBox(&quot;You did not select a file!&quot;)</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'return the name of the file</span>
	<span style="color: #FF8000;">Return</span> strFileName
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Function</span>
&nbsp;
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnOpenFile_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnOpenFile.<span style="color: #0000FF;">Click</span>
	<span style="color: #008080; font-style: italic;">'declare a string to the filename</span>
	<span style="color: #0600FF;">Dim</span> strFileNameAndPath <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> OpenFile<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
&nbsp;
	<span style="color: #008080; font-style: italic;">'check to see if they selected a file or just clicked cancel</span>
	<span style="color: #0600FF;">If</span> <span style="color: #000000;">&#40;</span>strFileNameAndPath <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
	    <span style="color: #008080; font-style: italic;">'Chastise the user for not selecting a file :)</span>
	    <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You did not select a file!&quot;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #FF8000;">Else</span>
	    <span style="color: #008080; font-style: italic;">'Begin doing whatever it is you would normally do with the file!</span>
	    <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You selected this file: &quot;</span> <span style="color: #008000;">&amp;</span> strFileNameAndPath <span style="color: #008000;">&amp;</span> vbCrLf <span style="color: #008000;">&amp;</span> _
		   <span style="color: #808080;">&quot;The filename is: &quot;</span> <span style="color: #008000;">&amp;</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0000FF;">Path</span>.<span style="color: #0000FF;">GetFileName</span><span style="color: #000000;">&#40;</span>strFileNameAndPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> vbCrLf <span style="color: #008000;">&amp;</span> _
		   <span style="color: #808080;">&quot;Located in: &quot;</span> <span style="color: #008000;">&amp;</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0000FF;">Path</span>.<span style="color: #0000FF;">GetDirectoryName</span><span style="color: #000000;">&#40;</span>strFileNameAndPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> vbCrLf <span style="color: #008000;">&amp;</span> _
		   <span style="color: #808080;">&quot;It has the following extension: &quot;</span> <span style="color: #008000;">&amp;</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #0000FF;">Path</span>.<span style="color: #0000FF;">GetExtension</span><span style="color: #000000;">&#40;</span>strFileNameAndPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> vbCrLf <span style="color: #008000;">&amp;</span> _
		   <span style="color: #808080;">&quot;The file was created on &quot;</span> <span style="color: #008000;">&amp;</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #008000;">File</span>.<span style="color: #0000FF;">GetCreationTime</span><span style="color: #000000;">&#40;</span>strFileNameAndPath<span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> vbCrLf <span style="color: #008000;">&amp;</span> _
		   <span style="color: #808080;">&quot;The file was last written to on &quot;</span> <span style="color: #008000;">&amp;</span> System.<span style="color: #0000FF;">IO</span>.<span style="color: #008000;">File</span>.<span style="color: #0000FF;">GetLastWriteTime</span><span style="color: #000000;">&#40;</span>strFileNameAndPath<span style="color: #000000;">&#41;</span> _
	    <span style="color: #000000;">&#41;</span>
	<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/09/howto-use-the-openfiledialog-box-in-vbnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Use the Progress Bar in VB.NET and C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/#comments</comments>
		<pubDate>Tue, 01 Sep 2009 03:32:38 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=566</guid>
		<description><![CDATA[The progress bar is one of those universal objects that everyone recognizes, it's useful when doing a large or long task. For example, if your updating/deleting/copying a bunch of files you can update the progress bar as you modify each file. [...]]]></description>
			<content:encoded><![CDATA[<p>The progress bar is one of those universal objects that everyone recognizes, it&#8217;s useful when doing a large or long task.  For example, if your updating/deleting/copying a bunch of files you can update the progress bar as you modify each file.<span id="more-566"></span></p>
<div id="attachment_567" class="wp-caption aligncenter" style="width: 298px"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/ProgressBarApp.jpg" alt="Progress Bar App with VB.NET and C#" title="Progress Bar App with VB.NET and C#" width="288" height="121" class="size-full wp-image-567" /><p class="wp-caption-text">Progress Bar App with VB.NET and C#</p></div>
<p>There are several lines of code to pay attention to, let me outline them here in further detail.<br />
<b>Line 7</b> &#8211; we can think of the maximum as how many steps their are.  We can say we want a 1000 steps, or only 20 steps.  This makes it useful if you want to update a random number of objects stored in an array, in that case we could store the <i>ProgressBar1.Maximum = UBound(arrSomeArray)</i>.<br />
<b>Line 9</b> &#8211; we are just initializing our progress bar to 0<br />
<b>Line 11</b> &#8211; we make the progress bar visible.  This step is up to you, I infrequently use the progress bar and I usually keep it hidden until I have a reason to display it.  If your progress bar is already visible you can delete this line of code<br />
<b>Line 13</b> &#8211; this line is completely unrelated to the progress bar, whatever value is specified in the <i>Sleep</i> argument is how long your application will wait to update.  In this application, I decided to wait 1000 milliseconds (or 1 second) before I goto the next step, this will allow us to see the progress bar update so we can simulate a test scenario.<br />
<b>Line 15-29</b> &#8211; This is just updating the progress bar, then waiting some more, nothing to special going on here. As you can see the value I am raising the progress bar is completely arbitrary.<br />
<b>Line 30</b> &#8211; Print out a message box saying complete<br />
<b>Line 31</b> &#8211; Hide the progress bar so that it is no longer visible, we&#8217;ve already told the user that the task is complete, there&#8217;s no need to continue showing the progress bar. Again, this line of code is entirely up to you.</p>
<p><b>This is the code for a VB.NET progress bar example</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</span>
&nbsp;
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> Button1.<span style="color: #0000FF;">Click</span>
    <span style="color: #008080; font-style: italic;">'Set the total number of steps to 100 (or 100%)</span>
    ProgressBar1.<span style="color: #0000FF;">Maximum</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
    <span style="color: #008080; font-style: italic;">'Set the initial value of the progress bar to 0% completed</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span>
    <span style="color: #008080; font-style: italic;">'If your progress bar is already visible you don't need this. But this is one of those objects I like to hide when I'm not using it</span>
    ProgressBar1.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">True</span>
    <span style="color: #008080; font-style: italic;">'This next line tells your application to wait or go to sleep for 1000ms / 1 second</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    <span style="color: #008080; font-style: italic;">'Update the progress bar to 15% completed</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">15</span>
    <span style="color: #008080; font-style: italic;">'Wait for another second</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    <span style="color: #008080; font-style: italic;">'Update to 30% complete</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">30</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">45</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">60</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">75</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">90</span>
    System.<span style="color: #0000FF;">Threading</span>.<span style="color: #0000FF;">Thread</span>.<span style="color: #0000FF;">Sleep</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">1000</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Value</span> <span style="color: #008000;">=</span> <span style="color: #FF0000;">100</span>
    <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Complete!&quot;</span><span style="color: #000000;">&#41;</span>
    ProgressBar1.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">False</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><b>This is the source code for a C# progress bar example</b><br />
The code only varies slightly in C#, I&#8217;ll make sure to explain any differences.  Besides the semicolons at the end of every line, only lines 12, 31, and 32 differ from the VB.NET example.<br />
<b>Line 12, Line 32</b> &#8211; Boolean values must be in lower case.<br />
<b>Line 31</b> &#8211; Showing a message box is slightly different in VB.NET, if you didn&#8217;t add the following headers <i>using System.Windows.Forms;</i> in your source code, then you will need to specify the full class name.  I included it so that this example can work on as many peoples projects as possible.  If you are already including <i>Systems.Windows.Forms</i> then you can show a message box by replacing line 31 with: <i>MessageBox.Show(&#8220;Complete!&#8221;);</i></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #666666;">//Complete source code is available at:</span>
<span style="color: #666666;">//http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/</span>
&nbsp;
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button1_Click<span style="color: #008000;">&#40;</span>object sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">//Set the total number of steps to 100 (or 100%)</span>
    progressBar1.<span style="color: #007788;">Maximum</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Set the initial value of the progress bar to 0% completed</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//If your progress bar is already visible you don't need this. But this is one of those objects I like to hide when I'm not using it</span>
    progressBar1.<span style="color: #007788;">Visible</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">true</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//This next line tells your application to wait or go to sleep for 1000ms / 1 second</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Update the progress bar to 15% completed</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">15</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Wait for another second</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Update to 30% complete</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">30</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">45</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">60</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">75</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">90</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Threading</span>.<span style="color: #007788;">Thread</span>.<span style="color: #007788;">Sleep</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">1000</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Value</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">100</span><span style="color: #008080;">;</span>
    System.<span style="color: #007788;">Windows</span>.<span style="color: #007788;">Forms</span>.<span style="color: #007788;">MessageBox</span>.<span style="color: #007788;">Show</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Complete!&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
    progressBar1.<span style="color: #007788;">Visible</span> <span style="color: #000080;">=</span> <span style="color: #0000ff;">false</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-use-the-progress-bar-in-vb-net-and-c-sharp/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Center A Form in VB.NET and C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 05:41:30 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Microsoft]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=550</guid>
		<description><![CDATA[I've often found it necessary to center a form on my screen using the pure code, but it's not as easy as <i>Me.center</i> in VB or <i>this.center()</i> in C# so I wrote some code to work around that. Using the code below you can center you application on your monitor in just 3 lines of code using either VB.NET or C#. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve often found it necessary to center a form on my screen using the pure code, but it&#8217;s not as easy as <i>Me.center</i> in Visual Basic or <i>this.center()</i> in C# so I wrote some code to work around that. Using the code below you can center you application on your monitor in just 3 lines of code using either VB.NET or C#.<span id="more-550"></span></p>
<p>The first thing you&#8217;ll notice is that I&#8217;m using <i>Screen.PrimaryScreen.WorkingArea</i> and not <i>Screen.PrimaryScreen.Bounds</i>, the bounds of the screen will give me the actual height/width of the monitor as coordinates.  But what it doesn&#8217;t take into account like the WorkingArea does are any docked items, such as the toolbar.  The WorkingArea returns the Bounds, and subtracts off any area unusable by the program to give us the &#8220;true&#8221; center.</p>
<p><b>(Source Code) Recenter your window using VB.NET</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</span>
<span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> Button1_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> Button1.<span style="color: #0000FF;">Click</span>
    <span style="color: #008080; font-style: italic;">'Get the working area of the screen and assign it to a rectangle object</span>
    <span style="color: #0600FF;">Dim</span> rect <span style="color: #FF8000;">As</span> Rectangle <span style="color: #008000;">=</span> Screen.<span style="color: #0000FF;">PrimaryScreen</span>.<span style="color: #0000FF;">WorkingArea</span>
    <span style="color: #008080; font-style: italic;">'Divide the screen in half, and find the center of the form to center it</span>
    <span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Top</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>rect.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span>.<span style="color: #0000FF;">Height</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
    <span style="color: #FF8000;">Me</span>.<span style="color: #0600FF;">Left</span> <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>rect.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> <span style="color: #000000;">&#40;</span><span style="color: #FF8000;">Me</span>.<span style="color: #0600FF;">Width</span> <span style="color: #008000;">/</span> <span style="color: #FF0000;">2</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span></pre></td></tr></table></div>

<p><b>(Source Code) Recenter your window using C#</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">//This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #666666;">//Complete source code is available at:</span>
<span style="color: #666666;">//http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/</span>
<span style="color: #0000ff;">private</span> <span style="color: #0000ff;">void</span> button1_Click<span style="color: #008000;">&#40;</span>object sender, EventArgs e<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">//Get the working area of the screen and assign it to a rectangle object   </span>
   Rectangle rect <span style="color: #000080;">=</span> Screen.<span style="color: #007788;">PrimaryScreen</span>.<span style="color: #007788;">WorkingArea</span><span style="color: #008080;">;</span>
    <span style="color: #666666;">//Divide the screen in half, and find the center of the form to center it</span>
   <span style="color: #0000dd;">this</span>.<span style="color: #007788;">Top</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>rect.<span style="color: #007788;">Height</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span>.<span style="color: #007788;">Height</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
   <span style="color: #0000dd;">this</span>.<span style="color: #007788;">Left</span> <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span>rect.<span style="color: #007788;">Width</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span> <span style="color: #000040;">-</span> <span style="color: #008000;">&#40;</span><span style="color: #0000dd;">this</span>.<span style="color: #007788;">Width</span> <span style="color: #000040;">/</span> <span style="color: #0000dd;">2</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-center-a-form-in-vb-net-and-c-sharp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Cut/Copy/Paste into the Clipboard using VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/#comments</comments>
		<pubDate>Mon, 31 Aug 2009 04:45:56 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=527</guid>
		<description><![CDATA[In this example, I'll show you how to cut, copy, paste and clear text in the clipboard. Cutting and copying text is really straight forward, pasting text requires just a little bit of checking. For example, we want to check to see what the clipboard contains before we try and do something like pasting an image into a text box. [...]]]></description>
			<content:encoded><![CDATA[<p>In this example, I&#8217;ll show you how to cut, copy, paste and clear text in the clipboard. Cutting and copying text is really straight forward, pasting text requires just a little bit of checking.  For example, we want to check to see what the clipboard contains before we try and do something like pasting an image into a text box.<span id="more-527"></span></p>
<p>To copy text, its just a simple one-liner:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span></pre></div></div>

<p>To cut text, it&#8217;s almost as simple as copying it, but we need to remember to delete the data from the text box once it&#8217;s been copied:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span></pre></div></div>

<p>To paste text there&#8217;s several things we have to worry about like I mentioned above.  We first want to check what&#8217;s in the clipboard and verify that the contents of the clipboard can be pasted into whatever field/object we are trying to paste them into.  In this example, I&#8217;m going to use the GetText method to make sure I only get the text from the clipboard and paste it into the text field.  In the example below, I&#8217;ll get the data from the clipboard, then check to see if it is text before pasting it.</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> Clipboard.<span style="color: #0000FF;">GetText</span></pre></div></div>

<p><div id="attachment_529" class="wp-caption aligncenter" style="width: 228px"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/CutCopyPasteApp.jpg" alt="Cut Copy Paste for .NET Applications" title="Cut Copy Paste for .NET Applications" width="218" height="140" class="size-full wp-image-529" /><p class="wp-caption-text">Cut Copy Paste for .NET Applications</p></div> Here are the names for each of the objects in the above photo, txtTextBox, btnCut, btnCopy, btnPaste each represent the text box, cut button, copy button, and paste button respectively.  I&#8217;ll use the same variable names in each programming language below.</p>
<h2>&nbsp; </h2>
<p><b>This is the code for the above program written in VB.NET</b></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This code was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/</span>
&nbsp;
<span style="color: #FF8000;">Public</span> <span style="color: #0600FF;">Class</span> Form1
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnCut_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnCut.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Checks to see if the user selected anything</span>
        <span style="color: #0600FF;">If</span> txtTextBox.<span style="color: #0000FF;">SelectedText</span> &lt;&gt; <span style="color: #808080;">&quot;&quot;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'Good, the user selected something</span>
            <span style="color: #008080; font-style: italic;">'Copy the information to the clipbaord</span>
            Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">'Since this is a cut command, we want to clear whatever </span>
            <span style="color: #008080; font-style: italic;">'text they had selected when they clicked cut</span>
            txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If there was no text selected, print out an error message box</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No text is selected to cut&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnCopy_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnCopy.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Checks to see if the user selected anything</span>
        <span style="color: #0600FF;">If</span> txtTextBox.<span style="color: #0000FF;">SelectedText</span> &lt;&gt; <span style="color: #808080;">&quot;&quot;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'Copy the information to the clipboard</span>
            Clipboard.<span style="color: #0000FF;">SetText</span><span style="color: #000000;">&#40;</span>txtTextBox.<span style="color: #0000FF;">SelectedText</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If no text was selected, print out an error message box</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No text is selected to copy&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
&nbsp;
    <span style="color: #FF8000;">Private</span> <span style="color: #0600FF;">Sub</span> btnPaste_Click<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> sender <span style="color: #FF8000;">As</span> System.<span style="color: #FF0000;">Object</span>, <span style="color: #FF8000;">ByVal</span> e <span style="color: #FF8000;">As</span> System.<span style="color: #0000FF;">EventArgs</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Handles</span> btnPaste.<span style="color: #0000FF;">Click</span>
        <span style="color: #008080; font-style: italic;">'Get the data stored in the clipboard</span>
        <span style="color: #0600FF;">Dim</span> iData <span style="color: #FF8000;">As</span> IDataObject <span style="color: #008000;">=</span> Clipboard.<span style="color: #0000FF;">GetDataObject</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-style: italic;">'Check to see if the data is in a text format</span>
        <span style="color: #0600FF;">If</span> iData.<span style="color: #0000FF;">GetDataPresent</span><span style="color: #000000;">&#40;</span>DataFormats.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span> <span style="color: #FF8000;">Then</span>
            <span style="color: #008080; font-style: italic;">'If it's text, then paste it into the textbox</span>
            txtTextBox.<span style="color: #0000FF;">SelectedText</span> <span style="color: #008000;">=</span> <span style="color: #0600FF;">CType</span><span style="color: #000000;">&#40;</span>iData.<span style="color: #0000FF;">GetData</span><span style="color: #000000;">&#40;</span>DataFormats.<span style="color: #0000FF;">Text</span><span style="color: #000000;">&#41;</span>, <span style="color: #FF8000;">String</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'If it's not text, print a warning message</span>
            <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Data in the clipboard is not availble for entry into a textbox&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Class</span></pre></td></tr></table></div>

<p>Now in general, I don&#8217;t think that the clipboard should be cleared by the programmer, it should be cleared by the user.  But if you have a legitimate reason to clear the clipboard, here&#8217;s the code to do just that:</p>

<div class="wp_syntax"><div class="code"><pre class="vbnet" style="font-family:monospace;">Clipboard.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-cutcopypaste-text-into-clipboard-using-vb-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Make Your Computer Talk with VB.NET Application (and Source Code)</title>
		<link>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/#comments</comments>
		<pubDate>Sun, 30 Aug 2009 02:57:25 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Downloads]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=502</guid>
		<description><![CDATA[I was playing around with COM objects in Windows and discovered that I could access the SAPI.SpVoice interface and make Microsoft Windows talk to me. Well needless to say I had to rush and develop and application to do just that. I uploaded a simple applicaton which will just say whatever you type in as an argument. For example <i>SpeakToMeConsole.exe Hello World</i> will make your computer speak the words "Hello World." The part that really amazes me is that the guts of this program is only 2 lines long, and it can even that can reduced down to 1 line if we create an anonymous instance of SAPI.SpVoice object. [...]]]></description>
			<content:encoded><![CDATA[<p>I was playing around with COM objects in Windows and discovered that I could access the SAPI.SpVoice interface and make Microsoft Windows talk to me.  Well needless to say I had to rush and develop and application to do just that.  I uploaded a simple applicaton which will just say whatever you type in as an argument.  For example <i>SpeakToMeConsole.exe Hello World</i> will make your computer speak the words &#8220;Hello World.&#8221;  The part that really amazes me is that the guts of this program is only 2 lines long, and it can even that can reduced down to 1 line if we create an anonymous instance of SAPI.SpVoice object.<span id="more-502"></span></p>
<p>The reason I created it as a console application and not a windows app is because I envisioned this program only really only having a valid function when it&#8217;s called from another application. Or even better, you want to spook your girlfriend or parents by making their laptop talk to them when it turns on!  Whatever your reasons are, enjoy! Oh and let me know how you use this program in the comments.</p>
<div id="attachment_506" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.brangle.com/downloads/SpeakToMe/v1.0/SpeakToMeConsole.exe"><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/download-button.jpg" alt="Download SpeakToMe App" title="Download SpeakToMe App" width="150" height="144" class="size-full wp-image-506" /></a><p class="wp-caption-text">Download SpeakToMe App</p></div>
<p>Here is the complete source code to the above application. Let me know what you think in the comments!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">'This application was developed by Gerardo Lopez and was downloaded from www.brangle.com</span>
<span style="color: #008080; font-style: italic;">'Complete source code is available at:</span>
<span style="color: #008080; font-style: italic;">'http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-app-source-code/</span>
&nbsp;
&nbsp;
Module Module1
    <span style="color: #008080; font-style: italic;">'We want to make sure we grab any arguments as args so that we speak them    </span>
    <span style="color: #0600FF;">Sub</span> Main<span style="color: #000000;">&#40;</span><span style="color: #FF8000;">ByVal</span> args <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #008080; font-style: italic;">'If there are no arguments UBound will return -1</span>
        <span style="color: #008080; font-style: italic;">'Therefore we want to make sure to let the user know how to run the app if </span>
        <span style="color: #008080; font-style: italic;">'they don't enter any arguments</span>
        <span style="color: #0600FF;">If</span> <span style="color: #0600FF;">UBound</span><span style="color: #000000;">&#40;</span>args<span style="color: #000000;">&#41;</span> &gt; <span style="color: #008000;">-</span><span style="color: #FF0000;">1</span> <span style="color: #FF8000;">Then</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Generate an empty string, we'll use this to concatenate all of our arguments </span>
            <span style="color: #008080; font-style: italic;">'together so we can pass it to the narrator</span>
            <span style="color: #0600FF;">Dim</span> <span style="color: #FF8000;">input</span> <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> <span style="color: #008000;">=</span> <span style="color: #808080;">&quot;&quot;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Concat all of our arguments together and make sure to put a space in </span>
            <span style="color: #008080; font-style: italic;">'between them so the words don't run together</span>
            <span style="color: #FF8000;">For</span> <span style="color: #0600FF;">Each</span> arg <span style="color: #FF8000;">As</span> <span style="color: #FF8000;">String</span> In args
                <span style="color: #FF8000;">input</span> <span style="color: #008000;">=</span> <span style="color: #FF8000;">input</span> <span style="color: #008000;">+</span> arg <span style="color: #008000;">+</span> <span style="color: #808080;">&quot; &quot;</span>
            <span style="color: #FF8000;">Next</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">'Create an object and gain access to the narrator</span>
            <span style="color: #0600FF;">Dim</span> voice <span style="color: #008000;">=</span> <span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SAPI.SpVoice&quot;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #008080; font-style: italic;">'Tells the narrator what to say</span>
            voice.<span style="color: #0000FF;">Speak</span><span style="color: #000000;">&#40;</span><span style="color: #FF8000;">input</span><span style="color: #000000;">&#41;</span>
        <span style="color: #FF8000;">Else</span>
            <span style="color: #008080; font-style: italic;">'The is where we tell the user what to say if they didn't enter any arguments</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;No arguments specified&quot;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Try this instead: SpeakToMe.exe Hello World&quot;</span><span style="color: #000000;">&#41;</span>
            Console.<span style="color: #0000FF;">WriteLine</span><span style="color: #000000;">&#40;</span>vbCrLf <span style="color: #008000;">+</span> vbCrLf <span style="color: #008000;">+</span> <span style="color: #808080;">&quot;Visit www.brangle.com for other apps&quot;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span>
    <span style="color: #0600FF;">End</span> <span style="color: #0600FF;">Sub</span>
<span style="color: #0600FF;">End</span> Module
<span style="color: #008080; font-style: italic;">'The End</span></pre></td></tr></table></div>

<p>To run this program from the command line, you can type in something like the following:</p>
<pre>SpeakToMeConsole.exe Hello World</pre>
<p>And here is the beautiful one-liner!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">CreateObject</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;SAPI.SpVoice&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Speak</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;hello from brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/make-your-computer-talk-with-vb-net-application-and-source-code/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Shutdown, Restart, Log off your computer with VB.NET or C#</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 08:27:06 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Sever 2003]]></category>
		<category><![CDATA[Vista]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[Windows 7]]></category>
		<category><![CDATA[XP]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=458</guid>
		<description><![CDATA[This is extremely easy using VB.NET or C# (pronounced C sharp) and using the built in windows EXE file <i>shutdown.exe</i>. To shutdown, restart, or log off your computer is as simple as entering 1 line into your program, it just so happens that the 1 line is identical whether you're using VB.NET or C#. [...]]]></description>
			<content:encoded><![CDATA[<p>This is extremely easy using VB.NET or C# (pronounced C sharp) and the built in windows EXE file <i>shutdown.exe</i>.  To shutdown, restart, or log off your computer is as simple as entering 1 line into your program, it just so happens that the 1 line is identical whether you&#8217;re using VB.NET or C#.<span id="more-458"></span></p>
<p>To shutdown/turn off your computer, just execute the following line of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-s -t 0&quot;</span>)</pre></td></tr></table></div>

<p>To restart/reboot your computer, just execute the following line of code:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-r -t 0&quot;</span>)</pre></td></tr></table></div>

<p>To log off your computer, just execute the following line of code (and yes, that&#8217;s a lowercase L, not the number 1):</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-l -t 0&quot;</span>)</pre></td></tr></table></div>

<p>The number zero at the end of each of those examples is how long the computer should wait in seconds before shutting down/restarting/etc&#8230; In this example, I&#8217;m going to shutdown the computer in 5 minutes (5 minutes * 60 seconds = 300 seconds)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;">System.Diagnostics.Process.Start(<span style="color: #800000;">&quot;shutdown.exe&quot;</span>, <span style="color: #800000;">&quot;-s -t 300&quot;</span>)</pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-shutdown-restart-log-off-your-computer-with-vb-net-or-c/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>How to Create Message Box Pop Ups in VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/#comments</comments>
		<pubDate>Thu, 27 Aug 2009 07:25:00 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=431</guid>
		<description><![CDATA[Creating different types of messages boxes in Visual Basic is a simple one line statement. I'm going to run through how to create several different types of message boxes in this tutorial, including OK Only, OK/Cancel, Abort/Retry/Ignore, and a Critical message box. [...]]]></description>
			<content:encoded><![CDATA[<p>Creating different types of messages boxes in Visual Basic is a simple one line statement.  I&#8217;m going to run through how to create several different types of message boxes in this tutorial, including OK Only, OK/Cancel, Abort/Retry/Ignore, and a Critical message box.<span id="more-431"></span></p>
<p>The simplest message box, it only includes an OK button&#8230;</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World!&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOnly.jpg" alt="MsgBoxOnly" title="MsgBoxOnly" width="161" height="100" class="alignnone size-full wp-image-434" /><br />
<br /><br /><br /></p>
<p>Ok, so the title of the message box the name of the project, let&#8217;s add our own title as the third argument, but first we&#8217;ll need to tell VB that we want to have this message box act as an OK only.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Hello World!&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkOnly</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOnlyWithTitle.jpg" alt="MsgBoxOnlyWithTitle" title="MsgBoxOnlyWithTitle" width="143" height="100" class="alignnone size-full wp-image-435" /><br />
<br /><br /><br /></p>
<p>The next message box is the OK/Cancel with a custom title.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Visit brangle.com?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkCancel</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxOKCancelWithTitle.jpg" alt="MsgBoxOKCancelWithTitle" title="MsgBoxOKCancelWithTitle" width="185" height="100" class="alignnone size-full wp-image-439" /><br />
<br /><br /><br /></p>
<p>OK great, but this time lets detect whether the user clicked OK or Cancel.  If the user clicks OK, We&#8217;ll launch my website <img src='http://www.brangle.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  otherwise we&#8217;ll do nothing.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">If</span> <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Visit brangle.com?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">OkCancel</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">=</span> MsgBoxResult.<span style="color: #0600FF;">Ok</span> <span style="color: #FF8000;">Then</span>
     Process.<span style="color: #0000FF;">Start</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;http://www.brangle.com/&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

<p><br /><br /><br /></p>
<p>Let&#8217;s try using an Abort/Retry/Ignore message box.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">Dim</span> result <span style="color: #FF8000;">As</span> DialogResult
result <span style="color: #008000;">=</span> <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Corrupt File. Try Again?&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">AbortRetryIgnore</span>, <span style="color: #808080;">&quot;www.brangle.com&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">If</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Abort</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to abort opening the file</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked abort&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">ElseIf</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Retry</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to retry opening the file</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked retry&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #FF8000;">ElseIf</span> result <span style="color: #008000;">=</span> Windows.<span style="color: #0000FF;">Forms</span>.<span style="color: #0000FF;">DialogResult</span>.<span style="color: #0600FF;">Ignore</span> <span style="color: #FF8000;">Then</span>
   <span style="color: #008080; font-style: italic;">'Do some action to ignore</span>
   <span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;You clicked ignore&quot;</span><span style="color: #000000;">&#41;</span>
<span style="color: #0600FF;">End</span> <span style="color: #0600FF;">If</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxAbortRetryIgnore.jpg" alt="MsgBoxAbortRetryIgnore" title="MsgBoxAbortRetryIgnore" width="266" height="100" class="alignnone size-full wp-image-450" /><br />
<br /><br /><br /></p>
<p>Now let&#8217;s launch a message box as critical, this will display the red icon with x thru it</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="vbnet" style="font-family:monospace;"><span style="color: #0600FF;">MsgBox</span><span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;File not found!&quot;</span>, MsgBoxStyle.<span style="color: #0600FF;">Critical</span>, <span style="color: #808080;">&quot;Error&quot;</span><span style="color: #000000;">&#41;</span></pre></td></tr></table></div>

<p><img src="http://www.brangle.com/wordpress/wp-content/uploads/2009/08/MsgBoxCritical.jpg" alt="MsgBoxCritical" title="MsgBoxCritical" width="146" height="119" class="alignnone size-full wp-image-452" /><br />
<br /><br /><br /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/how-to-create-message-box-pop-ups-in-vbnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check If File Exists with VB.NET</title>
		<link>http://www.brangle.com/wordpress/2009/08/check-if-file-exists-wit-vb-net/</link>
		<comments>http://www.brangle.com/wordpress/2009/08/check-if-file-exists-wit-vb-net/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 00:02:53 +0000</pubDate>
		<dc:creator>lopezg</dc:creator>
				<category><![CDATA[VB.NET]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://www.brangle.com/wordpress/?p=340</guid>
		<description><![CDATA[I was creating an application in Visual Basic the other day and I couldn't remember how to check to see if a file exists, so I thought I would do a quick example to see if a file exitsts. If the file exists, the program will continue on, however, if the file doesn't exist you will get a message box saying that the file does not exist, and the application will exit. [...]]]></description>
			<content:encoded><![CDATA[<p>I was creating an application in Visual Basic the other day and I couldn&#8217;t remember how to check to see if a file exists, so I thought I would do a quick example to see if a file exitsts.  If the file exists, the program will continue on, however, if the file doesn&#8217;t exist you will get a message box saying that the file does not exist, and the application will exit.<span id="more-340"></span></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #8D38C9; font-weight: bold;">If</span> System.IO.File.Exists(<span style="color: #800000;">&quot;C:\MyDocs\MyFile.txt&quot;</span>) = <span style="color: #00C2FF; font-weight: bold;">False</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
   MsgBox(<span style="color: #800000;">&quot;Field does not exist!&quot;</span>, MsgBoxStyle.Critical, <span style="color: #800000;">&quot;File Not Found&quot;</span>)
   Application.<span style="color: #E56717; font-weight: bold;">Exit</span>()
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span></pre></td></tr></table></div>

<p>If you have an <i>Imports System.IO</i> call in your program, then you can shorten the method call by deleting the <i>System.IO</i> class name, which would give you.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #8D38C9; font-weight: bold;">If</span> File.Exists(<span style="color: #800000;">&quot;C:\MyDocs\MyFile.txt&quot;</span>) = <span style="color: #00C2FF; font-weight: bold;">False</span> <span style="color: #8D38C9; font-weight: bold;">Then</span>
   MsgBox(<span style="color: #800000;">&quot;Field does not exist!&quot;</span>, MsgBoxStyle.Critical, <span style="color: #800000;">&quot;File Not Found&quot;</span>)
   Application.<span style="color: #E56717; font-weight: bold;">Exit</span>()
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span></pre></td></tr></table></div>

<p>This method call is supported in .NET Framework version 3.5, 3.0, 2.0, 1.1, and 1.0.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.brangle.com/wordpress/2009/08/check-if-file-exists-wit-vb-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

