<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2923556872467743331</id><updated>2024-09-04T16:05:39.425-07:00</updated><category term="VTCC"/><category term="vb"/><category term="Virginia"/><category term="cool"/><category term="fun"/><category term="Tech"/><category term="programming"/><category term=".net"/><category term="Class"/><category term="Gas"/><category term="Mileage"/><category term="array"/><category term="arraylist"/><category term="box"/><category term="code"/><category term="core"/><category term="database"/><category term="derek"/><category term="efficiency"/><category term="game"/><category term="google"/><category term="learn"/><category term="loftis"/><category term="message"/><category term="multi"/><category term="pong"/><category term="skynet"/><category term="thread"/><category term="visual basic"/><category term="windows"/><title type='text'>Adventures in Programming with Visual Basic</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://vbadventures.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>5</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2923556872467743331.post-1117221484522423119</id><published>2010-11-04T09:11:00.000-07:00</published><updated>2012-01-22T07:36:40.844-08:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="cool"/><category scheme="http://www.blogger.com/atom/ns#" term="fun"/><category scheme="http://www.blogger.com/atom/ns#" term="game"/><category scheme="http://www.blogger.com/atom/ns#" term="pong"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Tech"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><category scheme="http://www.blogger.com/atom/ns#" term="Virginia"/><category scheme="http://www.blogger.com/atom/ns#" term="visual basic"/><category scheme="http://www.blogger.com/atom/ns#" term="VTCC"/><title type='text'>Pong in VB.NET!</title><content type='html'>Hey there everyone, today I am going to show you how you can make pong in visual basic.net. &amp;nbsp;Please note that I am not going to put all of the code up here because that would be crazy.&lt;br /&gt;
&lt;br /&gt;
This is what the main form looks like:&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2BTL_DXXvy_VCwT5tPqKEn91REm6Zewh2ZSlaSUak81CPleyzCXXnVgABNZYUsiG7o1s7zkmSbsmh1xEQ9JPsLgCDE83EhkP_QC8Pfwu-mN6AJuqGpm65U1M8NxWDSuaC35Y8hCnucEE/s1600/ss1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2BTL_DXXvy_VCwT5tPqKEn91REm6Zewh2ZSlaSUak81CPleyzCXXnVgABNZYUsiG7o1s7zkmSbsmh1xEQ9JPsLgCDE83EhkP_QC8Pfwu-mN6AJuqGpm65U1M8NxWDSuaC35Y8hCnucEE/s320/ss1.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
This is all drawn with objects from the tool bar, no special graphics experience required.&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
Now lets look at some code:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
First of all, here are the variables used:&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim speed As Single = 10 &#39;This stores the speed of the ball&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim rndInst As New Random() &#39;This is a random number generator&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim xAng As Single = Math.Cos(rndInst.Next(5, 10)) &#39;X and Y&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim yAng As Single = Math.Sin(rndInst.Next(5, 10)) &#39;Angles&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim xVel As Single = xAng * speed &#39;The x and y velocities&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim yVel As Single = yAng * speed &#39;Computed from angle and speed&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim pScore As Int16 = 0 &#39;Player&#39;s score&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim cScore As Int16 = 0 &#39;Computer&#39;s score&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim cSpeed As Int16 = 10 &#39;Movement speed of computer (difficulty)&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim p As Boolean &#39;Is the game paused?&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;
&lt;br /&gt;
I used a timer to control the speed of the game, that way it doesn&#39;t go super fast on your brand new gaming computer. &amp;nbsp;To pause the game I used the code:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;p = True&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;gameTimer.Stop()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;speedTimer.Stop()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;lblPaused.Visible = True&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;The speed timer is used to increase the speed every few seconds to make the game progress (otherwise you would be hitting the ball between you and the computer until you or your computer died). &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;I made the user control their paddle by moving the mouse, their paddle would simply stay with the mouse as it moved. &amp;nbsp;The following code was used to&amp;nbsp;accomplish&amp;nbsp;this:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If e.Y &amp;gt; 29 And e.Y &amp;lt; Me.Height - 30 - playerPaddel.Height Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;playerPaddel.Location = New Point(playerPaddel.Location.X, e.Y)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;This code was placed in the &#39;mouseMove&#39; form event. &amp;nbsp;The logic in the if statement was used to keep the paddle within the vertical bounds of the screen.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;The computer&#39;s paddle tried to follow the ball no matter where the ball was in the hopes that it would be in the way of the ball when the ball reached it&#39;s side. &amp;nbsp;The following code was used for the &#39;AI&#39;:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If gameBall.Location.Y &amp;gt; compPaddle.Location.Y Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If compPaddle.Location.Y &amp;lt; Me.Height - 40 - playerPaddel.Height Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If compPaddle.Location.Y - (gameBall.Location.Y) &amp;gt; -cSpeed Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; compPaddle.Location = New Point(compPaddle.Location.X, gameBall.Location.Y)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Else&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; compPaddle.Location = New Point(compPaddle.Location.X, compPaddle.Location.Y + cSpeed)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;The first if statement just decides if the computer needs to move. &amp;nbsp;If it is already at the same level as the ball, then it does not need to move. &amp;nbsp;The second if statement decides if the computer paddle needs to move the full&amp;nbsp;amount&amp;nbsp;it can, or if a smaller&amp;nbsp;amount&amp;nbsp;will get it where it wants to be. &amp;nbsp;Finally, if it did need to move, and it did need to go as far as it can, then that is exactly what it does.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;To update the location of the game ball, the following code was used:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;gameBall.Location = New Point(gameBall.Location.X + xVel, gameBall.Location.Y + yVel)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;I think that is pretty self-explanatory, so I will move on. &amp;nbsp;(On a completly unrelated note, the text editor I am using is saying that &#39;yVel&#39; is spelled wrong, but &#39;xVel&#39; is not. &amp;nbsp;I don&#39;t know what the deal is there, I am pretty sure that xVel is not a word.) &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;The last piece of interesting code is the code that decides when the ball has hit a paddle. &amp;nbsp;The following was used to complete this task:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If gameBall.Bounds.IntersectsWith(playerPaddel.Bounds) Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; gameBall.Location = New Point(playerPaddel.Location.X - gameBall.Size.Width, gameBall.Location.Y)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; xVel = -xVel&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;The same code was used for the walls and for the computer&#39;s paddle. &amp;nbsp;It basically asks if the bounds of the ball are intersecting with the bounds of the player&#39;s paddle. &amp;nbsp;If they are, it changes the position of the ball so that it is not inside the paddle and then makes the ball travel in the opposite x direction. &amp;nbsp;This results in a very realistic bounce effect without even using elastic physics!&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Well, that is pretty much all I have to say, &amp;nbsp;I hope you enjoyed this and hopefully learned something. &amp;nbsp;Until next time, &#39;Happy Coding!&#39;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/1117221484522423119'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/1117221484522423119'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/2010/11/pong-in-vbnet.html' title='Pong in VB.NET!'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2BTL_DXXvy_VCwT5tPqKEn91REm6Zewh2ZSlaSUak81CPleyzCXXnVgABNZYUsiG7o1s7zkmSbsmh1xEQ9JPsLgCDE83EhkP_QC8Pfwu-mN6AJuqGpm65U1M8NxWDSuaC35Y8hCnucEE/s72-c/ss1.png" height="72" width="72"/></entry><entry><id>tag:blogger.com,1999:blog-2923556872467743331.post-7905298824180186737</id><published>2010-11-03T19:24:00.000-07:00</published><updated>2010-11-04T09:12:13.223-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="code"/><category scheme="http://www.blogger.com/atom/ns#" term="cool"/><category scheme="http://www.blogger.com/atom/ns#" term="core"/><category scheme="http://www.blogger.com/atom/ns#" term="efficiency"/><category scheme="http://www.blogger.com/atom/ns#" term="fun"/><category scheme="http://www.blogger.com/atom/ns#" term="multi"/><category scheme="http://www.blogger.com/atom/ns#" term="thread"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><category scheme="http://www.blogger.com/atom/ns#" term="VTCC"/><title type='text'>Multi-threading With Visual Basic</title><content type='html'>Ok, today we are going to talk about multi-threading. &amp;nbsp;I would give this lesson a difficulty of MODERATE not because it is difficult to code it, but because multi-threading can be a bit confusing conceptually.&lt;br /&gt;
&lt;br /&gt;
First off, what is multi-threading and why is it useful? &amp;nbsp;Well, when your program is running normally, aka you are not using multi-threading, it can only execute one instruction at a time. &amp;nbsp;Only one line of code is running at any given time. &amp;nbsp;If you use multi-threading, you can be running as many lines of code at once as you want. &amp;nbsp;Now don&#39;t go and try to make a program where each line of code has its own thread and think you have discovered ultimate efficiency, because there are a few catches to multi-threading. &amp;nbsp;Any segments of code that run at the same time cannot be dependent on each other. &amp;nbsp;For example, if you have two functions, and the output of the first function is used as input for the second, you cannot run them at the same time. &amp;nbsp;If the first one isn&#39;t finished, the second one can&#39;t start. &amp;nbsp;Another catch to multi-threading is that if you are using a single core computer, the benefits of multi-threading will not be as great. &amp;nbsp;This is because when there are multiple threads on a single core computer, they cannot truly run at the same time, so instead, the take turns running a little bit. &amp;nbsp;This occurs so quickly that they appear to be running at the same time, but in reality they are not. &amp;nbsp;If you have a computer with more than one processor core, then your computer can actually run more than one instruction at the same time. .&lt;br /&gt;
&lt;br /&gt;
On to the programming...&lt;br /&gt;
&lt;br /&gt;
To create a new thread, you declare a variable of type thread.&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim newThread as Thread&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Then you must&amp;nbsp;initialize&amp;nbsp;it as a new thread. &amp;nbsp;The new function for threads accepts an&amp;nbsp;argument&amp;nbsp;of type ThreadStart. &amp;nbsp;The best way to handle this is to create a new ThreadStart. &amp;nbsp;The argument for this new sub is &#39;AddressOf&#39; and the name of the subroutine that you want the new thread to run.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;newThread = new Thread(new ThreadStart(AddressOf doStuff))&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;That code assumes that you have defined a subroutine named &#39;doStuff&#39;. &amp;nbsp;For the subroutine that you want the new thread to run, you can put just about anything in it. &amp;nbsp;In one program I created, I wanted to use every core the computer had to find prime numbers. &amp;nbsp;I did this by creating a loop that created a new thread for each processor and added them to an arraylist of threads. &amp;nbsp;Then each one was told to run the same subroutine that found prime numbers. &amp;nbsp;I made this subroutine a loop so that the threads would run&amp;nbsp;continuously&amp;nbsp;until I stopped them. &amp;nbsp;That is one way you can use multi-threading, but there are many more. &amp;nbsp;Say for example you are writing a game and you want the character&#39;s stats to be updated every half of a second&amp;nbsp;regardless&amp;nbsp;of what the program is doing. You could create a timer that would run the update subroutine on a&amp;nbsp;separate&amp;nbsp;thread every half a second. &amp;nbsp;This would allow the stats to update even if the rest of the program was busy. &amp;nbsp;For that example it is very important that you do not let any of the other threads modify the controls that your update thread is using, if that happens the entire universe may unravel at it&#39;s seams. &amp;nbsp;Not really but it would be bad so just don&#39;t do it.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;That is about all I have to say on multi-threading, I hope you enjoyed reading this and hopefully you learned something. &amp;nbsp;Multi-threading is a powerful tool, especially in today&#39;s world of many core computers, multi-threading is the way of the future.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;On a side note, I just realized that I am writing about programming and I didn&#39;t even provide a link to free software that you can use to program in. Tsk, tsk, on me...&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;So here it is:&amp;nbsp;&lt;a href=&quot;http://www.microsoft.com/express/downloads/#2010-Visual-Basic&quot;&gt;Visual Basic 2010 Express&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;
To download visual basic 2010 express, just go to the visual basic header and expand it, then select the language that you prefer. &amp;nbsp;This is free software that is provided by Microsoft, so enjoy it.&lt;br /&gt;
&lt;br /&gt;
Note: If this link does not work because you are reading this way after it was written, just google &#39;Visual Studio Express Download&#39;&lt;br /&gt;
Wait, I will even do that for you:&amp;nbsp;&lt;a href=&quot;http://www.google.com/search?q=visual+studio+express+download&quot;&gt;Click here to Google it!&lt;/a&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Thanks for reading, if you have any good ideas for more topics, feel free to email them to me.&lt;/span&gt;&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div&gt;&lt;br /&gt;
&lt;/div&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/7905298824180186737'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/7905298824180186737'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/2010/11/multi-threading-with-visual-basic.html' title='Multi-threading With Visual Basic'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author></entry><entry><id>tag:blogger.com,1999:blog-2923556872467743331.post-3513940262378872452</id><published>2010-11-01T05:18:00.000-07:00</published><updated>2010-11-04T09:12:32.201-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="cool"/><category scheme="http://www.blogger.com/atom/ns#" term="fun"/><category scheme="http://www.blogger.com/atom/ns#" term="google"/><category scheme="http://www.blogger.com/atom/ns#" term="learn"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="skynet"/><category scheme="http://www.blogger.com/atom/ns#" term="Tech"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><category scheme="http://www.blogger.com/atom/ns#" term="Virginia"/><category scheme="http://www.blogger.com/atom/ns#" term="VTCC"/><title type='text'>Best Way To Learn Programming</title><content type='html'>Ok, first of all this is excluding the obvious answer of going to a programming class. &amp;nbsp;This is also assuming that you have enough basic programming&amp;nbsp;knowledge&amp;nbsp;that most&amp;nbsp;beginner&amp;nbsp;tutorials are kind of a waste of time. &amp;nbsp;This is a phase that many self taught programmers get stuck in. &amp;nbsp;They can program enough that writing &#39;Hello World&#39; isn&#39;t going to teach them anything. &amp;nbsp;Unfortunately&amp;nbsp;there are not near as many intermediate tutorials out there as there are beginner tutorials. &amp;nbsp;However there is still hope for self teaching.&lt;br /&gt;
&lt;br /&gt;
The method I have used to expand my programming knowledge after the beginner stage was to simple write lots of programs. &amp;nbsp;Any time I would think of something that could be done by the computer, I would make it into a program. &amp;nbsp;I got to the point where I wanted to program but could not think of any ideas of what to make. &amp;nbsp;At that point I started to ask the people around me if they had any ideas of programs that they would like to use but have never seen. &amp;nbsp;I have found that a very good way to learn&amp;nbsp;programming&amp;nbsp;is to just program. &amp;nbsp;My&amp;nbsp;recontamination&amp;nbsp;to anyone who wants to learn programming is to write every program that comes to mind. &amp;nbsp;Even if you are not sure how to do everything that will be needed for that program, go ahead and start it and when you find you need to do something that you have no clue how to do, google it. If you can&#39;t figure out what google tells you or there is not very much info on the topic you need, you could also find help at a talk board for the language you are using. &amp;nbsp;If Visual Basic .NET is your thing, which I would think it is since you are reading this, then&amp;nbsp;&lt;a href=&quot;http://www.vbdotnetforums.com/&quot;&gt;VB.NET Forums&lt;/a&gt;&amp;nbsp;is a pretty good place to go for help. &amp;nbsp;When you are thinking of ideas to make, it is good to be ambitious, but only to a point. &amp;nbsp;You must keep your ideas realistic, you don&#39;t know how badly I would like to write SKYNET, but that just isn&#39;t going to happen from one person with no AI experience. &amp;nbsp;You can make the program do something very complex or difficult, but you need to keep the scale&amp;nbsp;relatively&amp;nbsp;small or you will have to devote a huge&amp;nbsp;amount&amp;nbsp;of time to writing it and you won&#39;t be able to learn other things.&lt;br /&gt;
&lt;br /&gt;
So&amp;nbsp;basically, the best way, in my opinion, to learn programming is to&amp;nbsp;practice. &amp;nbsp;I know that is a&amp;nbsp;foreign&amp;nbsp;concept to many people. &amp;nbsp;But practice really does help. &amp;nbsp;Also try to work together with other programmers, sometimes they will have a&amp;nbsp;different&amp;nbsp;way of doing things that you may like.&lt;br /&gt;
&lt;br /&gt;
I hope you enjoyed this and maybe learned something. &amp;nbsp;Remember if you have any ideas for future topics, please email them to me.</content><link rel='replies' type='application/atom+xml' href='http://vbadventures.blogspot.com/feeds/3513940262378872452/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2923556872467743331/3513940262378872452' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/3513940262378872452'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/3513940262378872452'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/2010/11/best-way-to-learn-programming.html' title='Best Way To Learn Programming'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2923556872467743331.post-7318236970444797817</id><published>2010-10-31T16:03:00.000-07:00</published><updated>2010-11-04T09:12:49.171-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="array"/><category scheme="http://www.blogger.com/atom/ns#" term="arraylist"/><category scheme="http://www.blogger.com/atom/ns#" term="Class"/><category scheme="http://www.blogger.com/atom/ns#" term="cool"/><category scheme="http://www.blogger.com/atom/ns#" term="database"/><category scheme="http://www.blogger.com/atom/ns#" term="fun"/><category scheme="http://www.blogger.com/atom/ns#" term="Gas"/><category scheme="http://www.blogger.com/atom/ns#" term="Mileage"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><category scheme="http://www.blogger.com/atom/ns#" term="Virginia"/><category scheme="http://www.blogger.com/atom/ns#" term="VTCC"/><title type='text'>Custom Classes</title><content type='html'>Alright, today we are going to talk about custom classes. &amp;nbsp;This is, in my opinion, a really cool aspect of Object&amp;nbsp;Orientated&amp;nbsp;Programming. &amp;nbsp;This allows you to create custom data types that can be used throughout your project. &amp;nbsp;Not only does this save tons of code, but it makes keeping your program organized easier and makes everything look neater. &lt;br /&gt;
&lt;br /&gt;
The difficulty is EASY!!!&lt;br /&gt;
&lt;br /&gt;
Ok, let&#39;s say you are writing a program that will track gas mileage for cars. &amp;nbsp;Now lets pretend that you are writing the piece of code that will deal with adding a new trip. &amp;nbsp;Let&#39;s say you have a form that has places to put in the different pieces of data. &amp;nbsp;Let&#39;s also assume that you have a database class that is used to read and write from the database. You could write:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim tripMileage as Int16&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim tripDate as Date&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim gasUsed as Double&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;DataBase.AddTrip(tripMileage, tripDate, gasUsed)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;And that would work fine. &amp;nbsp;But when you got to a point where you wanted to list all of the trips a user had put in, what are you going to do?&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;You could:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim tripMileage() as Int16&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim tripDate() as Date&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim gasUsed() as Double&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;This would be creating arrays of each type to use to store the data for each trip. &amp;nbsp;The biggest problem with that is you must know beforehand how many trips you are dealing with. &amp;nbsp;Also I personally never liked using arrays like this. &amp;nbsp;What I would&amp;nbsp;recommended&amp;nbsp;doing is create a class called Trip.vb and using it to store trip information as its own data type. &amp;nbsp;Ex:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Public Class Trip&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;Public tripMileage as Int16&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;Public tripDate as Date&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;Public gasUsed as Double&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;Public sub new()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;tripMileage = 0&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;tripDate = new Date()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;gasUsed = 0.0&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp;End Sub&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End Class&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;Then you could have the sub that gives you the list of every trip just give you an ArrayList of type Trip. &amp;nbsp;You would use these trips as data types in your programming like this:&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim t as new Trip()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;t = DataBase.getNewestTrip()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;labelTripMileage.Text = t.tripMileage&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;labelTripDate.Text = t.tripDate.ToShortDateString()&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;labelGasUsed.Text = t.gasUsed&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;labelGasMileage.Text = Math.Round(t.gasUsed / t.tripMileage, 2)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;As you can see the variable t is of type Trip, this can make things a lot easier when programming to have a data type that is exactly what you are dealing with in your program. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;I hope you had fun and learned something. &amp;nbsp;If you have any good ideas for topics, feel free to email them to me.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Times, &#39;Times New Roman&#39;, serif;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbadventures.blogspot.com/feeds/7318236970444797817/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2923556872467743331/7318236970444797817' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/7318236970444797817'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/7318236970444797817'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/2010/10/custom-classes.html' title='Custom Classes'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2923556872467743331.post-2908725692404229428</id><published>2010-10-06T10:31:00.000-07:00</published><updated>2010-11-04T09:13:05.982-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="box"/><category scheme="http://www.blogger.com/atom/ns#" term="derek"/><category scheme="http://www.blogger.com/atom/ns#" term="loftis"/><category scheme="http://www.blogger.com/atom/ns#" term="message"/><category scheme="http://www.blogger.com/atom/ns#" term="programming"/><category scheme="http://www.blogger.com/atom/ns#" term="Tech"/><category scheme="http://www.blogger.com/atom/ns#" term="vb"/><category scheme="http://www.blogger.com/atom/ns#" term="Virginia"/><category scheme="http://www.blogger.com/atom/ns#" term="VTCC"/><category scheme="http://www.blogger.com/atom/ns#" term="windows"/><title type='text'>First Post</title><content type='html'>Alright, here we go...&lt;br /&gt;
This is my new blog. &amp;nbsp;First a little about me, I am a student at Virginia Tech. &amp;nbsp;I am currently a freshman. &amp;nbsp;I plan to study Computer Engineering. &amp;nbsp;All of the Visual Basic programming&amp;nbsp;knowledge&amp;nbsp;I have is self taught, I have never taken a VB class in my life, and I don&#39;t think I ever will. &amp;nbsp;I am a very big fan of the .NET framework, and I&amp;nbsp;absolutely&amp;nbsp;love Visual Studio. &amp;nbsp;I have never felt quite as comfortable with any other IDE (Integrated&amp;nbsp;Development&amp;nbsp;Environment) other than Visual Studio. &amp;nbsp;I started programming on a TI-84 calculator and then moved on to VB.NET which I still use to this day. &amp;nbsp;I can also program in JAVA and C#.NET and will soon be learning C++.&lt;br /&gt;
&lt;br /&gt;
But enough about me, lets do something with programming...&lt;br /&gt;
&lt;br /&gt;
For my fist example / lesson, I will be demonstrating the use of Message Boxes. &amp;nbsp;I know that this is a very elementary topic, but you have to start somewhere, and I don&#39;t want to scare away any new programmers out there.&lt;br /&gt;
&lt;br /&gt;
Difficulty: VERY EASY&lt;br /&gt;
&lt;br /&gt;
To use a message box as a notification, you simply use the code:&lt;br /&gt;
&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;MsgBox(&quot;Your message goes here!&quot;, ,&quot;Message Box Title&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;The reason I have that blank&amp;nbsp;argument&amp;nbsp;in there is because that is where the message box style would go. &amp;nbsp;For this example, we just wanted the message box to be a notification, so it only needs an &#39;OK&#39; button. &amp;nbsp;Lucky&amp;nbsp;for us that is the default style. &amp;nbsp;If you don&#39;t have a specific title in mind for the message box, you can simply close end the&amp;nbsp;argument&amp;nbsp;list with the message and the title will be the name of your application.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;If you want to ask a question with the message box, such as yes or no, you must set a style parameter. &amp;nbsp;You must also be ready to&amp;nbsp;receive&amp;nbsp;the answer.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;Dim ans As New MsgBoxResult&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;ans = MsgBox(&quot;Do you want to save before exiting?&quot;, MsgBoxStyle.YesNoCancel, &quot;Save?&quot;)&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If ans = MsgBoxResult.Yes Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &#39; Save and exit&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If ans = MsgBoxResult.No Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &#39; Don&#39;t save and exit&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;If ans = MsgBoxResult.Cancel Then&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp; &#39; Don&#39;t save and don&#39;t exit&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;End If&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: &#39;Courier New&#39;, Courier, monospace;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;As you can see here, I allowed there to be three&amp;nbsp;possible&amp;nbsp;answers to the question I asked: Yes, No, or Cancel. &amp;nbsp;First I had to declare a variable to store the user&#39;s response in. &amp;nbsp;This type of variable is aptly named &#39;MsgBoxResult&#39;. &amp;nbsp;Then I told the program to assign the value of the message box to the variable I declared. &amp;nbsp;As you can see for the style parameter, I used &#39;MsgBoxStyle.YesNoCancel&#39; &amp;nbsp;this tells the computer that you want a message box with those three options. &amp;nbsp;Now don&#39;t get confused, you can just put any old thing there, you must pick a style that exists. &amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;I can&#39;t think of much else to say about message boxes, that is about the limit of their functionality, so I will wrap up with a few notes to remember about message boxes.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;- While the message box is showing, the program does not run. &amp;nbsp;What I mean is the code stops at the line of the message box and waits for the user to dismiss the message box before continuing. &amp;nbsp;This can be&amp;nbsp;useful&amp;nbsp;if you want to check on variable values in the middle of a complex&amp;nbsp;operation.&amp;nbsp;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;- Message boxes usually pop up on top of your&amp;nbsp;application. &amp;nbsp;One exception to his is in ASP.NET (web page programming) &amp;nbsp;where the message box may not popup on top of the web browser. &amp;nbsp;I have not figured out how to fix this and it is very&amp;nbsp;annoying. &amp;nbsp;Due to that flaw, message boxes are virtually useless in web programming.&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: inherit;&quot;&gt;I hope you enjoyed this little talk, and hopefully learned something. &amp;nbsp;If you have a good idea for next time feel free to email them to me.&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://vbadventures.blogspot.com/feeds/2908725692404229428/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment/fullpage/post/2923556872467743331/2908725692404229428' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/2908725692404229428'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2923556872467743331/posts/default/2908725692404229428'/><link rel='alternate' type='text/html' href='http://vbadventures.blogspot.com/2010/10/first-post.html' title='First Post'/><author><name>Derek</name><uri>http://www.blogger.com/profile/06901668774390305424</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>