<?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-2315630515588192403</id><updated>2024-08-28T18:46:36.683-07:00</updated><category term="VB.NET"/><category term="Open File Dialogue Box"/><category term="A Times Table Programme"/><category term="A VB .NET menu Project"/><category term="Add Option Buttons"/><category term="Add a Checkbox"/><category term="Add a New Record"/><category term="Add a Toolbar to  Form"/><category term="Add a menu to Form"/><category term="Add coding button  Form"/><category term="AddUpdate Delete Records"/><category term="Adding a splash of colour"/><category term="Anchor Dock Controls form"/><category term="Appending Text to File"/><category term="Arrays and Index Number"/><category term="Arrays where boundaries"/><category term="Assigning Values to an Array"/><category term="Basic Math Symbols"/><category term="Breakpoints Debugging tool"/><category term="ByVal and ByRef in VB .NET"/><category term="Calculator Project"/><category term="Checkboxes"/><category term="Classes and Objects"/><category term="Code Time Table Programme"/><category term="Combo Box to form"/><category term="Controls using the Toolbox"/><category term="Copy a File"/><category term="Create Methods in Classes"/><category term="Create Properties in Classes"/><category term="Create Variables"/><category term="Create a New Project"/><category term="Create your  Classes"/><category term="Create your own Subs"/><category term="Creating Methods"/><category term="Creating Multiple Forms"/><category term="Cut Copy Paste Undo menu"/><category term="DataSets and Data Adaptors"/><category term="Database Wizard"/><category term="Delete a File"/><category term="Delete a Record"/><category term="Design Time Errors"/><category term="Display Data in DataSet"/><category term="Do Loops"/><category term="Equals Replace Insert"/><category term="Error Handling Debugging"/><category term="Filter files Open File Box"/><category term="For Loops"/><category term="Function in VB.NET"/><category term="Functions and Subs"/><category term="Getting started with VB.NET"/><category term="If Statements"/><category term="InStr Method"/><category term="Insert Images Picture Box"/><category term="Introduction to Loops"/><category term="KeyDown Event"/><category term="Logic Errors"/><category term="Message Box"/><category term="Modal and Non Modal Forms"/><category term="MouseDown Event"/><category term="Move a File"/><category term="Move through  Database"/><category term="Navigate a Database"/><category term="Open a Text File"/><category term="Parameters in your Subs"/><category term="Parameters with Functions"/><category term="Read Text File Line"/><category term="RunTime Errors"/><category term="Save File Dialogue Box"/><category term="Saving your work"/><category term="Section Three Exercises"/><category term="Select Case Statements"/><category term="Show and Hide Controls"/><category term="Split and Join"/><category term="Standard Modules - Part One"/><category term="Standard Modules Part Two"/><category term="String Variable Type"/><category term="String Variables"/><category term="Sub Menu to your Form"/><category term="Substring Method"/><category term="Text Property"/><category term="Textbox to the Form"/><category term="The Click Event"/><category term="The Form Load Event"/><category term="Trim Method"/><category term="Try ... Catch"/><category term="Use your New Property"/><category term="VB  Express and Databases"/><category term="VB .NET and Properties"/><category term="VB .NET database code"/><category term="Visual Basic .NET Forms"/><category term="What is  Text File?"/><category term="What is an Array?"/><category term="Write to a Text File"/><category term="about VB .NET variables"/><category term="add Shortcuts  Menu Items"/><category term="add code to a Menu"/><category term="between Char and Chars()"/><category term="code for the calculator"/><category term="get at Text in a textbox"/><category term="variables"/><category term="your first .NET code"/><title type='text'>VB.Net Tutorials</title><subtitle type='html'>wlanguages.co.cc HTML ,XHTML Tutorials ,Java Tutorials&#xa;SQL Tutorials ,JavaScript Tutorials ,CSS Tutorials&#xa; ,PHP Tutorials ,ASP.Net Tutorials ,MY SQL Tutorials ,VB.Net Tutorials ,C/C++ Tutorials ,Learn Ruby ,Learn Ruby on Rails ,Ruby on Rails-2.1 ,Learn Python ,Learn Python/DB ,Learn Python/CGI ,Learn Python/XML</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default?redirect=false'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default?start-index=26&amp;max-results=25&amp;redirect=false'/><author><name>Unknown</name><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>106</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2315630515588192403.post-271220614561757002</id><published>2010-09-19T04:16:00.000-07:00</published><updated>2011-04-10T04:37:00.640-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>The Code for the Time Table Programme</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As you can see from our&amp;nbsp;last lesson, we&#39;ve set up five Integer variables - number1, number2, multiplier, answer and i.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next thing we did was to pass whatever is in our two Textboxes straight into the two variable, number1 and number2. The start number goes into textbox one, and the end number goes into textbox2.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;number1 = Val(TextBox1.Text)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;number2 = Val(TextBox2.Text)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the next line of code, we set a starting value for the multiplier variable:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;multiplier = 2&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Then we had our two Loops, one inside the other. The first is the Do Loop:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Do While multiplier &amp;lt; 3&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;multiplier = multiplier + 1&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Loop&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This Do loop is exactly the same as the one you met before. All is does is go round and round While the variable called&amp;nbsp;&lt;b&gt;multiplier&lt;/b&gt;&amp;nbsp;is Less Than 3. The bit of code between Do and Loop just keeps adding one to whatever is in&amp;nbsp;&lt;b&gt;multiplier&lt;/b&gt;&amp;nbsp;(incrementing the variable).&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The other thing the Do Loop does is to execute our second loop - the For Loop. The For Loop gets executed each time around the Do Loop. The For Loop was this:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;For i = number1 To number2&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;answer = i * multiplier&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ListBox1.Items.Add(i &amp;amp; &quot; Times &quot; &amp;amp; multiplier &amp;amp; &quot; = &quot; &amp;amp; answer)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Next i&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Remember: the&amp;nbsp;&lt;b&gt;number1&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;number2&lt;/b&gt;&amp;nbsp;variables hold our numbers from the Textboxes. We set these to 1 and 10. So our first line of the For Loop is really this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;For i = 1 To 10&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re saying, &quot;Start a For Loop&quot;. Whatever is in the variable called number1, make that the starting number for the Loop. Put this value into the variable called&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;i&lt;/span&gt;. The end of the Loop will come when the variable called&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;i&lt;/span&gt;&amp;nbsp;has the value 10. Stop looping when you reach this value.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next part of the code reads this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;answer = i * multiplier&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This means, Put into the variable called&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;answer&lt;/span&gt;&amp;nbsp;the following sum: whatever is in the variable called&lt;span style=&quot;color: red;&quot;&gt;&amp;nbsp;i&lt;/span&gt;&amp;nbsp;multiplied by whatever is in the variable called&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;multiplier&lt;/span&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;(For a longer discussion on how to use the basic Maths symbols in VB .NET,&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So that says, put into the variable&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;answer&lt;/span&gt;&amp;nbsp;the sum of&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;i&lt;/span&gt;&amp;nbsp;times&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;multiplier&lt;/span&gt;. We&#39;re getting whatever is in&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;i&lt;/span&gt;&amp;nbsp;from the For loop. But we&#39;re getting whatever is in the variable called&lt;span style=&quot;color: red;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;from the Do Loop.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So Visual Basic will read the Do While line after noting that the number 2 has been put into the variable called multiplier. It will then check to see if the end of the loop condition has been met - multiplier is Less Than 3. As 2 is not Less Than 2, VB drops down to the next line.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next line is a For Loop -&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;For i = 1 To 10&lt;/span&gt;. This entire loop will be executed, and the code inside the For loop worked out.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So the For loop gets executed 10 times. Which means that our sum will get executed 10 times. When the end condition of the For loop is met, Visual Basic will exit the For Loop and drop down to the line of code below Next i. The code below Next i is this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;multiplier = multiplier + 1&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;What was inside the variable called multiplier was the number 2, so 2 + 1 = 3. And three is the new number inside the variable multiplier.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Then, Visual Basic drops down to the next line, which is Loop. So it goes back up to the Do While line of code&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Do While multiplier &amp;lt; 3&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The same question is asked again: Have we met the end condition for the Do Loop? The end condition was &quot;Keep looping while the variable called multiplier is Less Than 3&quot;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Because the value in multiplier is now equal to 3 and not less than 3, the end condition has been met. When the end condition is met, VB exists the Do loop.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;Borders3&quot; style=&quot;background-color: #f6eeda; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1pt; border-left-color: black; border-left-style: solid; border-left-width: 1pt; border-right-color: black; border-right-style: solid; border-right-width: 1pt; border-top-color: black; border-top-style: solid; border-top-width: 1pt; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em;&quot;&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Exercise&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the Do While line to this:&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Do While multiplier &amp;lt; 5&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Can you guess what will appear in your list box? Run your programme and find out.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Finally, a word about the line that displays your text in the list box. It was this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ListBox1.Items.Add(i &amp;amp; &quot; Times &quot; &amp;amp; multiplier &amp;amp; &quot; = &quot; &amp;amp; answer)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To add items to a list box with code, first you type the name of your list box:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ListBox1&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Type a full stop and a drop down list will appear. Select Items from the list.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ListBox1.Items&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Type another full stop and again a drop down list will appear. Select the Add Method&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ListBox1.Items.Add&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This method, not surprisingly, lets you add items to your list box. Whatever you want to add goes between a pair of round brackets:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ListBox1.Items.Add( )&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In between the round brackets, we have this for our code:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;i &amp;amp; &quot; Times &quot; &amp;amp; multiplier &amp;amp; &quot; = &quot; &amp;amp; answer&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;It might be a bit long, but there are 5 parts to it, all joined together by the concatenate symbol (&amp;amp;):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;i&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&quot; Times &quot;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;multiplier&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&quot; = &quot;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;answer&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The variable&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;i&amp;nbsp;&lt;/span&gt;holds the current value of the For Loop;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&quot; Times&lt;/span&gt;&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&quot;&lt;/span&gt;&amp;nbsp;is just direct text;&lt;span style=&quot;color: red;&quot;&gt;multiplier&lt;/span&gt;&amp;nbsp;holds the value we&#39;re multiplying by (our times table);&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;&quot; = &quot;&amp;nbsp;&lt;/span&gt;is again direct text; and&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;answer&lt;/span&gt;&amp;nbsp;is the answer to our times table sum.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;If you want to clear the items from a List box you can do this. At the top of the code, enter this line:&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;ListBox1.Items.Clear()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So instead of selecting Add from the final drop down list, select Clear.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;Borders3&quot; style=&quot;background-color: #f6eeda; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1pt; border-left-color: black; border-left-style: solid; border-left-width: 1pt; border-right-color: black; border-right-style: solid; border-right-width: 1pt; border-top-color: black; border-top-style: solid; border-top-width: 1pt; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em;&quot;&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Exercise&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add another textbox to your form. This will represent the &quot;times table&quot;. So far you have been getting this value directly from the code. For this exercise, get the multiplier value directly from the textbox. Add appropriate labels to all your textboxes.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The multiplier variable is the starting point for your &quot;times tables&quot;. What else do you need to amend in the code? Think about what happens if you entered a 5 into your new Textbox.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you enter a number 5 or greater, the code doesn&#39;t get executed! Can you understand why that is? If not, I suggest you go over this looping section again.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;/div&gt;&lt;div class=&quot;Borders3&quot; style=&quot;background-color: #f6eeda; border-bottom-color: black; border-bottom-style: solid; border-bottom-width: 1pt; border-left-color: black; border-left-style: solid; border-left-width: 1pt; border-right-color: black; border-right-style: solid; border-right-width: 1pt; border-top-color: black; border-top-style: solid; border-top-width: 1pt; font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; padding-bottom: 0.5em; padding-left: 0.5em; padding-right: 0.5em; padding-top: 0.5em;&quot;&gt;&lt;h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Exercise&lt;/div&gt;&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Amend the above code to solve the problem of the programme not being executed.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you successfully solved the problem, what else did you notice? Assuming that you added two labels to your new textboxes - &quot;Start At&quot; and &quot;End At&quot; - what happens if you enter a 3 in the Start At textbox and a 5 in the End At textbox? Will you actually get the 5 times table? What can you do so that the 5 times table is displayed? (Consider using a different Do Loop. What about a Do ... Until loop?)&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the next part, we&#39;ll take a closer look at the basic Maths symbols you can use in VB&amp;nbsp;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/271220614561757002/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/code-for-time-table-programme.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/271220614561757002'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/271220614561757002'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/code-for-time-table-programme.html' title='The Code for the Time Table Programme'/><author><name>Unknown</name><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-2315630515588192403.post-2217064536637613009</id><published>2010-09-19T04:10:00.000-07:00</published><updated>2011-04-10T04:37:00.645-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Try ... Catch in VB .NET</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;VB.NET has a inbuilt class that deals with errors. The Class is called&amp;nbsp;&lt;b&gt;Exception&lt;/b&gt;. When an exception error is found, an&amp;nbsp;&lt;b&gt;Exception object&lt;/b&gt;&amp;nbsp;is created. The coding structure VB.NET uses to deal with such Exceptions is called the Try … Catch structure.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the coding area for your button, type the word&amp;nbsp;&lt;b&gt;Try&lt;/b&gt;. Then hit the return key on your keyboard. VB.NET completes the rest of the structure for you:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Try&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Catch ex As Exception&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;End Try&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Try word means &quot;Try to execute this code&quot;. The Catch word means &quot;Catch any errors here&quot;. The ex is a variable, and the type of variable it is is an Exception object.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Move your line of code from the&amp;nbsp;previous section&amp;nbsp;to the Try part:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Try&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;rt1.LoadFile(&quot;C:\test10.txt&quot;, RichTextBoxStreamType.PlainText)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Catch ex As Exception&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;End Try&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you run your programme, VB will Try to execute any code in the Try part. If everything goes well, then it skips the Catch part. However, if an error occurs, VB.NET jumps straight to Catch. Add the following to your Catch part:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;MsgBox(ex.Message)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Your coding window should look like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Your coding window&quot; border=&quot;1&quot; height=&quot;258&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/DEBUG5.JPG&quot; width=&quot;570&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Because ex is an object variable, it now has its own Properties and methods. One of these is the Message property. Run your programme and test it out. Click your button. You should see the following error message:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;File Not Found Error&quot; height=&quot;107&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/FileNotFound.gif&quot; width=&quot;188&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The message is coming from the &quot;additional Information&quot; section of the error message we saw earlier, the one we didn&#39;t handle. But the point about this new message box is that it will not crash your programme. You have handled the Exception, and displayed an appropriate message for the user.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you know the kind of error that a programme might throw, you can get what Type it is from the Error message box you saw earlier. This one:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The File Not Found error&quot; height=&quot;233&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/errorFileNotFound.gif&quot; width=&quot;402&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the&amp;nbsp;&lt;b&gt;View Details&lt;/b&gt;&amp;nbsp;links under&amp;nbsp;&lt;b&gt;Actions&lt;/b&gt;&amp;nbsp;to see the following:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Details about the error thrown by VB NET&quot; height=&quot;300&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/FileNotFound_Details.gif&quot; width=&quot;542&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first line tells us the Type of Exception it is:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System.IO.FileNotFoundException&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can add this directly to the catch part. Previously, you were just catching any error that might be thrown:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Catch ex As Exception&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But if you know a &quot;file not found&quot; error might be thrown, you can add that to the Catch line, instead of Exception:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Catch ex As System.IO.FileNotFoundException&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can keep the Exception line as well. (You can have as many Catch parts as you want.) This will Catch any other errors that may occur:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Try&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;rt1.LoadFile(&quot;C:\test10.txt&quot;, RichTextBoxStreamType.PlainText)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Catch ex As System.IO.FileNotFoundException&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;MsgBox(ex.Message)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Catch ex As Exception&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;MsgBox(ex.Message)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Try&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There is one last part of the Try … Catch Statement that VB.NET doesn&#39;t add for you -&lt;b&gt;Finally&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Try&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Catch ex As Exception&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Finally&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;End Try&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;Finally&lt;/b&gt;&amp;nbsp;part is always executed, whether an error occurs or not. You typically add a Finally part to perform any cleanup operations that are needed. For example, you may have opened a file before going into a Try … Catch Statement. If an error occurs, the file will still be open. Whether an error occurs or not, you still need to close the file. You can do that in the&amp;nbsp;&lt;b&gt;Finally&lt;/b&gt;&amp;nbsp;part.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But Microsoft advise that you always use&amp;nbsp;&lt;b&gt;Try … Catch&lt;/b&gt;&amp;nbsp;Statements in your code. However, throughout the rest of this course, for convenience sake, we won&#39;t be using them much. Even when we should be.But that&#39;s no excuse for you not to use them!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/2217064536637613009/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/try-catch-in-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2217064536637613009'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2217064536637613009'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/try-catch-in-vb-net.html' title='Try ... Catch in VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-7807773538231105135</id><published>2010-09-02T09:49:00.000-07:00</published><updated>2011-04-10T04:37:00.649-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>About VB.Net</title><content type='html'>&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;DetailPagestablecontent&quot; id=&quot;tcontent1&quot; style=&quot;background-color: white; border-bottom-style: none; border-collapse: collapse; border-color: initial; border-color: initial; border-left-style: none; border-right-style: none; border-style: initial; border-top-style: none; border-width: initial; empty-cells: show; font-family: Tahoma; font-size: 11px; line-height: 14px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px; vertical-align: top; width: 634px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td id=&quot;tdCourse&quot; style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-color: initial; border-left-color: initial; border-left-style: initial; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 4px; vertical-align: top;&quot;&gt;&lt;span id=&quot;labelAboutThisCourse&quot;&gt;&lt;span class=&quot;DetailPagesContentHeading2&quot; style=&quot;display: block; font-weight: bold; margin-bottom: 0.4em;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAboutThisCourse&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAboutThisCourse&quot;&gt;&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Elements of this syllabus are subject to change.&lt;/div&gt;&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;This five-day instructor-led course provides students with the knowledge and skills needed to develop applications in Microsoft Visual Basic .NET for the Microsoft .NET platform. The course focuses on user interfaces, program structure, language syntax, and implementation details.&lt;/div&gt;&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;This is the first course in the Visual Basic .NET curriculum and will serve as the entry point for other .NET courses.&lt;/div&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-color: initial; border-left-color: initial; border-left-style: initial; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 4px; vertical-align: top;&quot;&gt;&lt;span id=&quot;labelAudienceDescription&quot;&gt;&lt;span class=&quot;DetailPagesContentHeading1&quot; style=&quot;display: block; font-weight: bold; margin-bottom: 0.2em;&quot;&gt;Audience Profile&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAudienceDescription&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAudienceDescription&quot;&gt;&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;This course is intended for both novice and experienced programmers who have a minimum of three months programming experience and have basic Microsoft Windows navigation skills.&lt;/div&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td style=&quot;background-attachment: initial; background-clip: initial; background-color: white; background-image: initial; background-origin: initial; background-position: initial initial; background-repeat: initial initial; border-bottom-style: none; border-bottom-width: 1px; border-color: initial; border-color: initial; border-left-color: initial; border-left-style: initial; border-left-width: 0px; border-right-style: none; border-right-width: 0px; border-style: initial; border-top-style: none; border-top-width: 0px; border-width: initial; padding-bottom: 0px; padding-left: 10px; padding-right: 10px; padding-top: 4px; vertical-align: top;&quot;&gt;&lt;span id=&quot;labelAtCourseCompletion&quot;&gt;&lt;span class=&quot;DetailPagesContentHeading1&quot; style=&quot;display: block; font-weight: bold; margin-bottom: 0.2em;&quot;&gt;At Course Completion&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAtCourseCompletion&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span id=&quot;labelAtCourseCompletion&quot;&gt;&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;After completing this course, students will be able to:&lt;/div&gt;&lt;ul style=&quot;margin-bottom: 0.1em; margin-left: 15px; margin-right: 15px; margin-top: 0px; padding-bottom: 0px; padding-left: 0px; padding-right: 0px; padding-top: 0px;&quot; type=&quot;disc&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create a simple Visual Basic .NET-based application based on the Windows Application template.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Use forms and controls to create a user interface.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create and use variables and arrays.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create and use Sub and Function procedures, including predefined functions.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Implement decision structures and loops by using conditional expressions.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Validate user input for fields, controls, and forms.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Apply object-oriented programming techniques to create classes, add methods, and add properties.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Resolve syntax, run-time, and logic errors by using the debugger and structured exception handling.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Enhance the user interface by adding menus, status bars, and toolbars.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Create a simple Visual Basic .NET-based Web Forms application that uses an XML Web Service.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Access and manipulate data in a Microsoft Access or Microsoft SQL Server™ database by using Microsoft ADO.NET.&lt;/div&gt;&lt;/li&gt;
&lt;li style=&quot;padding-bottom: 0.1em;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;Abstract&quot; style=&quot;font-family: Tahoma !important; font-size: 8.5pt !important; padding-bottom: 1px;&quot; xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;Build, package, and deploy an application.&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;/span&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/7807773538231105135/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/about-vb.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7807773538231105135'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7807773538231105135'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/09/about-vb.html' title='About VB.Net'/><author><name>Unknown</name><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-2315630515588192403.post-8267643259745976810</id><published>2010-08-26T14:12:00.000-07:00</published><updated>2011-04-10T04:37:00.653-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Getting started with VB.NET</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Launch your Visual Basic .NET or Visual Studio software. When the software first loads, you&#39;ll see a screen something like this one:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There&#39;s a lot happening on the start page. But basically, this is where you can start a new project, or open an existing one. The first Tab, Projects, is selected. At the moment, the area labelled &quot;Open an Existing Project&quot; is blank. This is what you&#39;ll see when you run the software for the first time (because you haven&#39;t created a project yet). When you create a project, the Name you gave it will be displayed on this page, as a hyperlink. Clicking the link will open the project.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;At the bottom of the screen, there are two buttons: &quot;New Project&quot; and &quot;Open Project&quot;. To get started, click the &quot;New Project&quot; button. When you do, you&#39;ll see this dialogue box appear:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;157&quot; src=&quot;http://www.homeandlearn.co.uk/NET/images/NewProjectDB.gif&quot; width=&quot;200&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As a beginner, you&#39;ll normally want the option selected: &quot;Windows Application&quot;, in the &quot;Visual Basic Projects&quot; folder. This means that you&#39;re going to be designing a programme to run on a computer running the Microsoft Windows operating system.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you look in the Name textbox at the bottom, you&#39;ll see it says &quot;WindowsApplication1&quot;. This is the default name for your projects. It&#39;s not a good idea to keep this name. After all, you don&#39;t want all of your projects to be called &quot;WindowsApplication1&quot;, &quot;WindowsApplication2&quot;, etc. So click inside this textbox and change this Name to the following:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;My First Project&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Keep the Location the same as the default. This is a folder inside of your &quot;My Documents&quot; folder called &quot;Visual Studio Projects&quot;. A new folder will then be created for you, and its name will be the one you typed in the &quot;Name&quot; textbox. All of your files for your first project are then saved in this folder.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the OK button, and the Visual Basic NET design time environment will open. It will look like the following (the 2008 edition is just the same):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;That&#39;s a very daunting piece of software, hey? Well, don&#39;t worry. We&#39;ll break it down bit by bit in the next few sections, and pretty soon you&#39;ll be zipping your way around it like a pro!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/8267643259745976810/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/getting-started-with-vbnet.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/8267643259745976810'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/8267643259745976810'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/getting-started-with-vbnet.html' title='Getting started with VB.NET'/><author><name>Unknown</name><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-2315630515588192403.post-4969417753828778081</id><published>2010-08-26T14:09:00.000-07:00</published><updated>2011-04-10T04:37:00.658-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Getting at Values on Other Forms</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The form with OK and Cancel buttons on it is not doing much good. We need it do some work for us. Let&#39;s turn the form into a Change Case dialogue box.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Design a Form like the one in the following image (this is&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;300&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aForm_p307.gif&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you&#39;ve designed your form, click back on Form1 and add a Textbox to it. When the button on Form1 is clicked, the dialogue box above will display. You can then select an option button to change the case to Upper, Lower or Proper case. This will happen when the OK button is clicked. Whatever text is in Texbox1 on Form1 will be changed accordingly.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Double click the OK button on&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;&amp;nbsp;to access the code. You should have the following:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Me.DialogResult = DialogResult.OK&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you want to refer to Texbox1 on Form1, you can&#39;t just do this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Form1.Textbox1.Text&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In previous version of VB, that code would be all right. You&#39;re saying &quot;Access the Text property of Textbox1 on Form1.&quot; The problem in VB.NET is that forms are Classes. They don&#39;t become objects until one is created from a Class. So the frmSecond Class knows nothing about Form1. It has no idea what it is.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The solution is to create a textbox object variable on Form1, and assign Textbox1 to this variable. But this variable has to be something that all Classes in the project can see.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So add this near the top of your code window for Form1 (add it just below the Inherits System.Windows.Forms.Form line, or Public Class Form1):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Public Shared tb As TextBox&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re setting up a variable which we&#39;ve called&amp;nbsp;&lt;b&gt;tb&lt;/b&gt;. A Textbox object is going to be stored in this variable. But notice that the variable is&amp;nbsp;&lt;b&gt;Public Shared&lt;/b&gt;. This way,&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;&amp;nbsp;will be able to see the variable.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the Form Load event for Form1, add the following line:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;tb = Textbox1&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When Form1 loads, the textbox called Textbox1 will be assigned to the tb variable. Now Textbox1 can be seen by frmSecond.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Go back to your code for the OK button on frmSecond. Add the following two lines at the top:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim ChangeCase As String&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ChangeCase = Form1.tb.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re setting up a String variable called ChangeCase. Whatever text is in Textbox1 of Form1 will then be assigned to the ChangeCase variable. But notice that as soon as you type a full stop after Form1, the&amp;nbsp;&lt;b&gt;tb&lt;/b&gt;&amp;nbsp;variable will be available in the pop up list:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;207&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aForm_p315.gif&quot; width=&quot;216&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Public variable called tb holds a reference to Textbox1 on Form1. When you type a full stop after the tb, you get a list popping up. The list is all the Properties and Methods that are available to Textbox1. One of these is the Text property.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We now only need to add the code that does the actual converting. So add this below the two lines you already have:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim ChangeCase As String&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ChangeCase = Form1.tb.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;If optUpper.Checked Then&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ChangeCase = ChangeCase.ToUpper&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ElseIf optLower.Checked Then&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ChangeCase = ChangeCase.ToLower&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ElseIf optProper.Checked Then&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ChangeCase = StrConv(ChangeCase, VbStrConv.ProperCase)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Form1.tb.Text = ChangeCase&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The three options buttons on our form were called&amp;nbsp;&lt;b&gt;optUpper&lt;/b&gt;,&amp;nbsp;&lt;b&gt;optLower&lt;/b&gt;&amp;nbsp;and&lt;b&gt;optProper&lt;/b&gt;. In the code, we&#39;re using an If Statement to see which of these was selected. The one that was chosen will have its&amp;nbsp;&lt;b&gt;Checked&lt;/b&gt;&amp;nbsp;property set to&amp;nbsp;&lt;b&gt;True&lt;/b&gt;. We then store into the variable&amp;nbsp;&lt;b&gt;ChangeCase&lt;/b&gt;&amp;nbsp;the converted text from the textbox. The final line puts the converted text back into Textbox1 on Form1. But you&#39;re coding window should look like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Change Case Code&quot; border=&quot;1&quot; height=&quot;391&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aFormCode_p316.gif&quot; width=&quot;449&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Note that the DialogResult.OK line is the final line of the code. When you&#39;re writing your code, make sure that optUpper, optLower and optProper are changed to whatever you called your Radio Buttons.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you&#39;re finished adding the code, run your programme. Enter some text into Textbox1. Then click the button that brings up the Change Case Dialogue box. Select an option from the three available, and the click OK. The text in Textbox1 should be converted.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Setting and Getting value from one form to another can be quite a tricky process at first. But once you get the hang of it you&#39;ll find it&#39;s not too difficult.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And that ends this section of this course. There&#39;s an awful lot more to learn about Windows Forms, and a bit of experimentation is needed before you become skilled in their use. But in a beginners course, you&#39;ve learned enough to be going on with.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4969417753828778081/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/getting-at-values-on-other-forms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4969417753828778081'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4969417753828778081'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/getting-at-values-on-other-forms.html' title='Getting at Values on Other Forms'/><author><name>Unknown</name><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-2315630515588192403.post-6682176915762291581</id><published>2010-08-26T14:08:00.000-07:00</published><updated>2011-04-10T04:37:00.663-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Modal and Non Modal Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Modal and Non Modal Forms</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A modal from is one that has to be dealt with before a user can continue. An example is the Change Case dialogue box in Microsoft Word. If you try to click away from the dialogue box, you&#39;ll here a beep to indicate an error. Until you click either the Cancel or OK buttons, the programme won&#39;t let you click anywhere else.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The second form you&#39;ve&amp;nbsp;just created&amp;nbsp;is called a Modeless form. These are forms than can be hidden or sent to the taskbar. You can then return to the main form or programme and do things with it.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A Modal form is sometimes called a dialogue box. And we&#39;ll see how to create one of these now.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add a second button to your Form1. Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;property of the new button to&lt;b&gt;btnDialogueBox&lt;/b&gt;. Double click the new button and add the following code:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim frmDialogue As New frmSecond&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;frmDialogue.ShowDialog()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To display a form as a Modal dialogue box, you use the&amp;nbsp;&lt;b&gt;ShowDialog&lt;/b&gt;&amp;nbsp;method. If you use the Show method, the form is displayed as a Modeless form.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme. Click your new button, and the second form should display. Move it out the way and try to click a button on Form1. You won&#39;t be able to. The second form has to be dealt with before you can access Form1.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When the form is a Modal dialogue box, you can create OK and Cancel buttons for it. VB.NET then has a trick up its sleeve for these types of buttons. We&#39;ll see that trick now.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;OK and Cancel Buttons&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the design environment, Click the Tab for your&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;. When the form is displayed in the design window, add two buttons to it (Make sure you&#39;re adding the buttons to the second form and NOT Form1). Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;property of the first button to&amp;nbsp;&lt;b&gt;btnOK&lt;/b&gt;, and the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;property of the second to&amp;nbsp;&lt;b&gt;btnCancel&lt;/b&gt;. Double click your OK button and add the following code to it:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Me.DialogResult = DialogResult.OK&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;Me&lt;/b&gt;&amp;nbsp;keyword refers to the current form. When you type a full stop, select&lt;b&gt;DialogResult&lt;/b&gt;&amp;nbsp;from the pop up list that appears. DialogResult is a property of the Form. It can accept a range of values. As soon as you type a space after the equals sign, you&#39;ll see a list with these values on it (VB NET 2008 only. In VB 2010, you have to type the DialogResult):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The DialogResults list&quot; height=&quot;136&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/addForm3.jpg&quot; width=&quot;156&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As you can see, in VB NET 2008, one of these values is&amp;nbsp;&lt;b&gt;DialogResult.OK&lt;/b&gt;. This indicates that you want to use this button as an OK button. When the button is clicked, VB.NET will return a result of OK for this button.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In VB NET 2010, type&amp;nbsp;&lt;b&gt;DialogResult&lt;/b&gt;&amp;nbsp;after the equals sign. Type a dot and you&#39;ll have this instead of the above image:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;173&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dialogue_result_2010.gif&quot; width=&quot;179&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Access the code for your Cancel button and add the following line:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Me.DialogResult = DialogResult.Cancel&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;For the Cancel button, we&#39;re just selecting&amp;nbsp;&lt;b&gt;DialogResult.Cancel&lt;/b&gt;&amp;nbsp;from the list. When the button is clicked, VB.NET will return a result of Cancel for this button.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can test to see what value is stored in&amp;nbsp;&lt;b&gt;Me.DialogResult&lt;/b&gt;. But you do that from the button that displays the form,&amp;nbsp;&lt;b&gt;Form1&lt;/b&gt;&amp;nbsp;for us.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So access your Form1 code, and locate the lines that display the second form. The two lines should be these:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Dim frmDialogue As New frmSecond&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;frmDialogue.ShowDialog()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the second line to this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If frmDialogue.ShowDialog() = DialogResult.OK Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;OK Button Clicked&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To get at the value of the button clicked, you test to see what result the&amp;nbsp;&lt;b&gt;ShowDialog&lt;/b&gt;property is. If the&amp;nbsp;&lt;b&gt;ShowDialog&lt;/b&gt;&amp;nbsp;property of&amp;nbsp;&lt;b&gt;frmDialogue&lt;/b&gt;&amp;nbsp;is&amp;nbsp;&lt;b&gt;OK&lt;/b&gt;&amp;nbsp;then you can execute the code that needs executing. If the Cancel button was clicked, however, you don&#39;t have to do anything: VB.NET will take of closing your Modal dialogue box for you!&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme and test it out. Click your button to bring up your Modal dialogue box. Click the OK button, and you should see the message box display. Bring the Modal dialogue box up a second time and then click the Cancel button. The form will just close down.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/6682176915762291581/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/modal-and-non-modal-forms.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/6682176915762291581'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/6682176915762291581'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/modal-and-non-modal-forms.html' title='Modal and Non Modal Forms'/><author><name>Unknown</name><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-2315630515588192403.post-6153107427809421677</id><published>2010-08-26T14:07:00.000-07:00</published><updated>2011-04-10T04:37:00.667-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Creating Multiple Forms"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Creating Multiple Forms in VB .NET</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;It&#39;s a rare programme that only has one form in it. Most programmes will have other forms. These other forms can be used for things like Find and Replace searches, extra formatting capabilities, to set Options for the programme, and a whole lot more besides. VB.NET let&#39;s you add as many forms as you want to your project. But the process is not quite so simple. We&#39;ll see how to do it, though.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can use the form you already have for this, the one with&amp;nbsp;the ToolStrip&amp;nbsp;on it (or start a new project, if you prefer). But from the VB.NET design environment, click the&amp;nbsp;&lt;b&gt;Project&lt;/b&gt;menu. From the drop down menu, click&lt;b&gt;&amp;nbsp;Add Windows Form&lt;/b&gt;. The Add New Item dialogue box appears.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Select&amp;nbsp;&lt;b&gt;Windows Form&lt;/b&gt;&amp;nbsp;under Templates. Then click inside the Name textbox at the bottom. Change the Name of the form to&amp;nbsp;&lt;b&gt;frmSecond.vb&lt;/b&gt;. Then click Add.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you are returned to the design environment, your new form will be displayed:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Two Forms created&quot; height=&quot;63&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/addFormED.jpg&quot; width=&quot;316&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To switch between forms, you can click the tabs. In the image, two tabs are displayed: Form1 (the original and first form), and our new form&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;ll write code to get this new form to display. But it will only appear when a button is clicked on Form1.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So click the tab for Form1, and add a button to this form. Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;property of the button to&amp;nbsp;&lt;b&gt;btnShowSecond&lt;/b&gt;. Then double click the button to access the code for it.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In order to display the second form, you have to bear in mind that Forms are Classes. So&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;&amp;nbsp;is a Class (as is Form1). You first have to create a new object from the class called frmSecond Class. Then call its Show method.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So add this code to your button&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim SecondForm As New frmSecond&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;SecondForm.Show()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first line sets up a variable called&amp;nbsp;&lt;b&gt;SecondForm&lt;/b&gt;. When you type &quot;&lt;b&gt;As New&lt;/b&gt;&quot;, you&#39;re asking VB.NET to create a New object. If you type a space, you&#39;ll see a pop up list. Type the&amp;nbsp;&lt;b&gt;frm&lt;/b&gt;&amp;nbsp;of frmSecond and you should see it displayed on the list. You can double click the item in the list to add it to your code. But what the line does is create a new Object from the Class called&amp;nbsp;&lt;b&gt;frmSecond&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once we have the Form Object stored in the variable, we can just use the Show method to display the form.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme and test it out. When you click your button, you should see the second form appear.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;However, there&#39;s a problem with this code. Click the button again and another copy of&lt;b&gt;frmSecond&lt;/b&gt;&amp;nbsp;appears. Keep clicking the button and your screen will be filled with the second form!&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To prevent this from happening, you can move the code that creates the form object. Move it right to the top of the coding window, just below&amp;nbsp;&lt;b&gt;Public Class Form1&lt;/b&gt;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The only code left in the button is the line that Shows the form. A new form object will now not be created every time the button is clicked. If you try it out, you should see only one form appear when the button is clicked, and not multiple forms.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/6153107427809421677/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/creating-multiple-forms-in-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/6153107427809421677'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/6153107427809421677'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/creating-multiple-forms-in-vb-net.html' title='Creating Multiple Forms in VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-2298210105445277904</id><published>2010-08-26T14:06:00.000-07:00</published><updated>2011-04-10T04:37:00.672-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Add a Toolbar to  Form"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Add a Toolbar to a Form</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;he toolbar is a very popular and much-used addition to a programme. It&#39;s difficult to think of a piece of software that doesn&#39;t make use of them. VB.NET lets you add toolbars to your forms, and the process is quite straightforward. Let&#39;s see how it&#39;s done:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Either start a new Windows project, or keep the one you currently have. To add a toolbar to the top of your form, expand the Toolbox and locate the ToolStrip control:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Toolstrip control in VB NET&quot; border=&quot;1&quot; height=&quot;137&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p304.gif&quot; width=&quot;200&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Double click the ToolStrip control, and it will be added to the top of your form:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;A Toolstrip has been added to a form&quot; height=&quot;91&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p305.gif&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You should also notice the ToolStrip object that appears at the bottom of the window:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Toolstrip object&quot; border=&quot;1&quot; height=&quot;56&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip2_p305.gif&quot; width=&quot;158&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;ToolStrips work by adding buttons and images to them. The button is then clicked, and an action performed.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click on your ToolStrip to select it. In the property box for the ToolStrip, you&#39;ll notice that it has the default Name of&amp;nbsp;&lt;b&gt;ToolStrip1&lt;/b&gt;. We&#39;ll keep this Name. But locate the Items (Collection) property:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Items property&quot; border=&quot;1&quot; height=&quot;274&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip3_p305.gif&quot; width=&quot;313&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the button with the three dots in it. This brings up the Items Collection Editor:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Items Collection Editor&quot; height=&quot;400&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p306.gif&quot; width=&quot;502&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To add a new button to your ToolStrip, click the&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;&amp;nbsp;button at the top. The button appears in the Members box (ToolStripButton1):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;ToolStripButton&quot; border=&quot;1&quot; height=&quot;315&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip2_p306.gif&quot; width=&quot;479&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Notice that the new button has its own list of properties, just to the right. To add an image to this new button, locate the Image property:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Properties of the ToolStripButton&quot; border=&quot;1&quot; height=&quot;312&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p307.gif&quot; width=&quot;251&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the small button with the 3 dots in it to bring up the Select Resource box:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Resources Dialogue Box&quot; height=&quot;343&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p308.gif&quot; width=&quot;489&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the image above, we&#39;ve selected &quot;Project resource file&quot;, and then clicked the Import button. We then navigated to some Bitmap images and imported the five that you can see in the screenshot above. (The Bitmap folder is amongst the files you download at the start of this book.) Click OK when you have imported some images. You will be returned to the Item Collection Editor. Click OK on this, as well. The ToolStrip on your form will then look like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;72&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip2_p308.gif&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The second of those images is a dropdown list of available ToolStrip options:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;ToolStrip options&quot; border=&quot;1&quot; height=&quot;207&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip3_p308.gif&quot; width=&quot;212&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So if you want, say, a separator instead of a button, select it from the list. This dropdown list will disappear when you run the form:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;76&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip4_p308.gif&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Repeat the steps outlined above, and add some more buttons to your ToolStrip. It should then look something like ours:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The completed ToolStrip&quot; height=&quot;75&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStrip_p309.gif&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If your ToolStrip images have a grey background, you can get rid of this by bringing up the Image Collection Editor again. Select a button, and then locate the property called ImageTransparentColor. The default is Magenta. Change it to Silver, which is one of the Custom colours (second grey down, on the left).&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Of course, if you click on the buttons nothing will happen. We need to write the code that gets them to work.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;text-align: left;&quot;&gt;Coding For your Toolbar buttons&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Double click your first ToolStripbutton to bring up the coding window. It should look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Coding window for a ToolStrip button&quot; border=&quot;1&quot; height=&quot;79&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStripCode_p309.gif&quot; width=&quot;502&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can place any code you like, here. Try a message box, as in the image below:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;107&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/aToolStripCode2_p309.gif&quot; width=&quot;501&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme and click your ToolStrip button. You should see the message box display. In a real programme, however, the code would be the same code for a menu item - it&#39;s just shortcut, after all!&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/2298210105445277904/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-toolbar-to-form.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2298210105445277904'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2298210105445277904'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-toolbar-to-form.html' title='Add a Toolbar to a Form'/><author><name>Unknown</name><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-2315630515588192403.post-71210258546230475</id><published>2010-08-26T14:05:00.000-07:00</published><updated>2011-04-10T04:37:00.676-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Anchor Dock Controls form"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Anchor and Dock Controls on a Form</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Anchoring and Docking&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Anchor and Dock properties of a form are two separate properties. Anchor refers to the position a control has relative to the edges of the form. A textbox, for example, that is anchored to the left edge of a form will stay in the same position as the form is resized. Docking refers to how much space you want the control to take up on the form. If you dock a control to the left of the form, it will stretch itself to the height of the form, but its width will stay the same. Let&#39;s take a look at some examples, to clear things up.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Anchoring&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Start a new windows projects. Add two textboxes to your form, and set the MultiLine properties of both to True. Change the height of the boxes.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click on Textbox1 and locate the Anchor property in the Properties box:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Anchor Property of the Textbox&quot; height=&quot;322&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/Anchor.jpg&quot; width=&quot;278&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The default is to anchor the control to the Top, Left edge of the form. Click the arrow to reveal a curious drop down box:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Anchor buttons&quot; height=&quot;128&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/Anchor2.jpg&quot; width=&quot;277&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The button in the middle represents your control. The big white areas are rather confusing - they don&#39;t actually do anything! To change the property, you click the smaller grey or white rectangles between the big white rectangle. Click again to deselect it. In the image below, the property has been changed so that the textbox is anchored to the Top, Left and Right sides of the form:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Textbox is anchored to the top, left, right of the Form&quot; height=&quot;126&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/Anchor3.jpg&quot; width=&quot;278&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next image has the textbox anchored to the Right and Bottom edges of the Form:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Right and Bottom anchoring&quot; height=&quot;129&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/Anchor4.jpg&quot; width=&quot;278&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Notice where the cursor is in the images, and what has been changed. Click the arrow on the drop down box to confirm your choices.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To see what effect this all has, do the following:&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Set the Anchor property of Textbox1 on the default of&amp;nbsp;&lt;b&gt;Top&lt;/b&gt;,&amp;nbsp;&lt;b&gt;Left&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the Anchor property of Textbox2 to&amp;nbsp;&lt;b&gt;None&lt;/b&gt;&amp;nbsp;(all the small rectangles should be white.)&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme and drag the edges of the Form outward. This will resize your form&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;What you should notice is that Textbox1 stays where it is, and that the left edge of Textbox2 moves.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Stop your programme from running. Change the Anchor properties of the two textboxes to anything you like. Run your form again and watch what happens. Try anchoring one textbox to the left and right of the form. Watch what happens.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But anchoring a control to an edge of the form is a useful property to get used to, if you have a form that can be resized and want your controls to stay where they are.&lt;/div&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Docking&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Docking is similar to Anchoring, but this time the control fills a certain area of the form. To see how it works, click on one of your textboxes and locate the Dock property. Click the arrow to reveal a drop down box:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Dock Property&quot; height=&quot;146&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/Dock.jpg&quot; width=&quot;278&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This time, all the rectangles are like buttons. You can only dock to one side at a time, and the default is None. Click a button to see what it does to your textbox. Click the middle one, and the textbox will Fill the whole form.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Docking is quite useful when used with the splitter control and panels, allowing you to create a Windows-style interface.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/71210258546230475/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/anchor-and-dock-controls-on-form.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/71210258546230475'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/71210258546230475'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/anchor-and-dock-controls-on-form.html' title='Anchor and Dock Controls on a Form'/><author><name>Unknown</name><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-2315630515588192403.post-7705612952692459782</id><published>2010-08-26T14:04:00.000-07:00</published><updated>2011-04-10T04:37:00.681-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Delete a Record"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Delete a Record using VB .NET</title><content type='html'>&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Deleting Records from a Database&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code to delete a record is a little easier than last time. Double click your&amp;nbsp;&lt;b&gt;btnDelete&lt;/b&gt;and add the following:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim cb As New OleDb.OleDbCommandBuilder(da)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).Delete()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MaxRows = MaxRows - 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = 0&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You&#39;ve met most of it before. First we set up a Command Builder. Then we have this line:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).&lt;span style=&quot;color: blue;&quot;&gt;Delete()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Just as there is an&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;&amp;nbsp;method of the DataSet Rows property, so there is a&amp;nbsp;&lt;b&gt;Delete&lt;/b&gt;method. You don&#39;t need anything between the round brackets, this time. We&#39;ve specified the Row to delete with:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Rows(&lt;span style=&quot;color: blue;&quot;&gt;inc&lt;/span&gt;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;variable is setting which particular Row we&#39;re on. When the&amp;nbsp;&lt;b&gt;Delete&lt;/b&gt;&amp;nbsp;method is called, it is this row that will be deleted.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;However, it will only be deleted from the DataSet. To delete the row from the underlying database, we have this again:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Command Builder, in conjunction with the Data Adapter, will take care of the deleting. All you need to is call the&amp;nbsp;&lt;b&gt;Update&lt;/b&gt;&amp;nbsp;method of the Data Adapter.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;MaxRows&lt;/b&gt;&amp;nbsp;line in the code just deducts 1 from the variable. This just ensures that the number of rows in the DataSet matches the number we have in the MaxRows variable.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We also reset the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;variable to zero, and call the&amp;nbsp;&lt;b&gt;NavigateRecords()&lt;/b&gt;&amp;nbsp;subroutine. This will mean that the first record is displayed, after a record has been deleted.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Try out your programme. Click the&amp;nbsp;&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button a few times to move to a valid record. Then click the&amp;nbsp;&lt;b&gt;Delete Record&lt;/b&gt;&amp;nbsp;button. The record will be deleted from the DataSet AND the database. The record that is then displayed will be the first one.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There&#39;s another problem, though: if you click the&amp;nbsp;&lt;b&gt;Delete Record&lt;/b&gt;&amp;nbsp;button before the&lt;b&gt;&amp;nbsp;Next Record&amp;nbsp;&lt;/b&gt;button, you&#39;ll get an error message. You can add an If Statement to check that the inc variable does not equal minus 1.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Another thing you can do is to display a message box asking users if they really want to delete this record. Here&#39;s one in action:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;126&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookMessage_p296.jpg&quot; width=&quot;275&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To get this in your own programme, add the following code to the very top of your Delete button code:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If MessageBox.Show(&quot;Do you really want to Delete this Record?&quot;, _&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&quot;Delete&quot;, MessageBoxButtons.YesNo, _&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MessageBoxIcon.Warning) = DialogResult.No Then&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue; font-weight: bold;&quot;&gt;&lt;br /&gt;
&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;Operation Cancelled&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Exit Sub&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;End If&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first three lines of the code are really one line. The underscore has been used to spread it out, so as to fit on this page.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we&#39;re using the new message box function:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;MessageBox.Show()&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In between the round brackets, we specifying the message to display, followed by a caption for the message box. We then have this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;MessageBoxButtons.&lt;span style=&quot;color: blue;&quot;&gt;YesNo&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You won&#39;t have to type all that out; you&#39;ll be able to select it from a popup list. But what it does is give you Yes and No buttons on your message box.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After typing a comma, we selected the&amp;nbsp;&lt;b&gt;MessageBoxIcon&lt;/b&gt;.Warning icon from the popup list.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But you need to check which button the user clicked. This is done with this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;= DialogResult.No&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Again, you select from a popup list. We want to check if the user clicked the No button. This will mean a change of mind from the user. A value of No will then be returned, which is what we&#39;re checking for in the If Statement.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code for the If Statement itself is this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;MsgBox(&quot;Operation Cancelled&quot;)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Exit Sub&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This will display another message for the user. But most importantly, the subroutine will be exited: we don&#39;t want the rest of the Delete code to be executed, if the user clicked the No button.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And that&#39;s it for our introduction to database programming. You not only saw how to construct a database programme using the Wizard, but how to write code to do this yourself. There is an awful lot more to database programming, and we&#39;ve just scratched the surface. But in a beginner&#39;s course, that&#39;s all we have time for.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The section that follows is all about Forms.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/7705612952692459782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/delete-record-using-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7705612952692459782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7705612952692459782'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/delete-record-using-vb-net.html' title='Delete a Record using VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-4410663255011182912</id><published>2010-08-26T14:03:00.000-07:00</published><updated>2011-04-10T04:37:00.687-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Add a New Record"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Add a New Record using VB .NET</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Add a New Record&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Adding a new record is slightly more complex. First, you have to add a new Row to the DataSet, then commit the new Row to the Database.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But the&amp;nbsp;&lt;b&gt;Add New Record&lt;/b&gt;&amp;nbsp;button on our form is quite simple. The only thing it does is to switch off other buttons, and clear the textboxes, ready for a new entry. Here&#39;s the code for your&amp;nbsp;&lt;b&gt;Add New Record&lt;/b&gt;&amp;nbsp;button:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;btnCommit.Enabled = True&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnAddNew.Enabled = False&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnUpdate.Enabled = False&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnDelete.Enabled = False&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtFirstName.Clear()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtSurname.Clear()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;So three buttons are switched off when the&amp;nbsp;&lt;b&gt;Add New Record&lt;/b&gt;&amp;nbsp;button is clicked, and one is switched on. The button that gets switched on is the Commit Changes button. The Enabled property of&amp;nbsp;&lt;b&gt;btnCommit&lt;/b&gt;&amp;nbsp;gets set to&amp;nbsp;&lt;b&gt;True&lt;/b&gt;. But, for this to work, you need to set it to&amp;nbsp;&lt;b&gt;False&lt;/b&gt;&amp;nbsp;when the form loads. So return to your Form. Click&amp;nbsp;&lt;b&gt;btnCommit&lt;/b&gt;&amp;nbsp;to select it. Then locate the&amp;nbsp;&lt;b&gt;Enabled&lt;/b&gt;&amp;nbsp;Property in the Properties box. Set it to&amp;nbsp;&lt;b&gt;False&lt;/b&gt;. When the Form starts up, the button will be switched off.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Clear/Cancel button can be used to switch it back on again. So add this code to your btnClear:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;btnCommit.Enabled = False&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnAddNew.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnUpdate.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnDelete.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = 0&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re switching the&amp;nbsp;&lt;b&gt;Commit Changes&lt;/b&gt;&amp;nbsp;button off, and the other three back on. The other two lines just make sure that we display the first record again, after the Cancel button is clicked. Otherwise the textboxes will all be blank.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To add a new record to the database, we&#39;ll use the&amp;nbsp;&lt;b&gt;Commit Change&lt;/b&gt;s button. So double click your&amp;nbsp;&lt;b&gt;btnCommit&lt;/b&gt;&amp;nbsp;to access its code. Add the following:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;If inc &amp;lt;&amp;gt; -1 Then&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Dim cb As New OleDb.OleDbCommandBuilder(da)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Dim dsNewRow As DataRow&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;dsNewRow = ds.Tables(&quot;AddressBook&quot;).NewRow()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;dsNewRow.Item(&quot;FirstName&quot;) = txtFirstName.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;dsNewRow.Item(&quot;Surname&quot;) = txtSurname.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows.Add(dsNewRow)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;MsgBox(&quot;New Record added to the Database&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnCommit.Enabled = False&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnAddNew.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnUpdate.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;btnDelete.Enabled = True&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;End If&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code is somewhat longer than usual, but we&#39;ll go through it.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first line is an If Statement. We&#39;re just checking that there is a valid record to add. If there&#39;s not, the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;variable will be on minus 1. Inside of the If Statement, we first set up a&amp;nbsp;&lt;b&gt;Command Builder&lt;/b&gt;,&amp;nbsp;as before. The next line is this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Dim dsNewRow As DataRow&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you want to add a new row to your DataSet, you need a&amp;nbsp;&lt;b&gt;DataRow&lt;/b&gt;&amp;nbsp;object. This line just sets up a variable called&amp;nbsp;&lt;b&gt;dsNewRow&lt;/b&gt;. The type of variable is a DataRow.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To create the new DataRow object, this line comes next:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;dsNewRow = ds.Tables(&quot;AddressBook&quot;).NewRow()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re just saying, &quot;Create a New Row object in the AddressBook DataSet, and store this in the variable called dsNewRow.&quot; As you can see,&amp;nbsp;&lt;b&gt;NewRow()&lt;/b&gt;&amp;nbsp;is a method of&lt;b&gt;ds.Tables&lt;/b&gt;. Use this method to add rows to your DataSet.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The actual values we want to store in the rows are coming from the textboxes. So we have these two lines:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;dsNewRow.Item(&quot;FirstName&quot;) = txtFirstName.Text&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;dsNewRow.Item(&quot;Surname&quot;) = txtSurname.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;dsNewRow&lt;/b&gt;&amp;nbsp;object we created has a Property called&amp;nbsp;&lt;b&gt;Item&lt;/b&gt;. This is like the Item property you used earlier. It represents a column in your DataSet. We could have said this instead:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;dsNewRow.&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;&amp;nbsp;= txtFirstName.Text&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;dsNewRow.&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;2&lt;/span&gt;)&lt;/span&gt;&amp;nbsp;= txtSurname.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;Item&lt;/b&gt;&amp;nbsp;property is now using the index number of the DataSet columns, rather than the names. The results is the same, though: to store new values in these properties. We&#39;re storing the text from the textboxes to our new Row.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We now only need to call the Method that actually adds the Row to the DataSet:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows.&lt;span style=&quot;color: blue;&quot;&gt;Add(&lt;span style=&quot;color: red;&quot;&gt;dsNewRow&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To add the Row, you use the&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;&amp;nbsp;method of the Rows property of the DataSet. In between the round brackets, you need the name of your DataRow (the variable&lt;b&gt;dsNewRow&lt;/b&gt;, in our case).&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You should know what the rest of the code does. Here&#39;s the next line:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Again, we&#39;re just using the&amp;nbsp;&lt;b&gt;Update&lt;/b&gt;&amp;nbsp;method of the Data Adapter, just like last time. The rest of the code just displays a message box, and resets the button.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But to add a new Row to a DataSet, here&#39;s a recap on what to do:&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Create a&amp;nbsp;&lt;b&gt;DataRow&lt;/b&gt;&amp;nbsp;variable&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Cretae an Object from this variable by using the&amp;nbsp;&lt;b&gt;NewRow()&lt;/b&gt;&amp;nbsp;method of the DataSet&amp;nbsp;&lt;b&gt;Tables&lt;/b&gt;&amp;nbsp;property&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Assign values to the&amp;nbsp;&lt;b&gt;Items&lt;/b&gt;&amp;nbsp;in the new Row&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Use the&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;&amp;nbsp;method of the DataSet to add the new row&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A little more complicated, but it does work! Try your programme out. Click your&amp;nbsp;&lt;b&gt;Add New Record&lt;/b&gt;&amp;nbsp;button. The textboxes should go blank, and three of the buttons will be switched off. Enter a new First Name and Surname, and then click the&amp;nbsp;&lt;b&gt;Commit Changes&lt;/b&gt;&amp;nbsp;button. You should see the message box telling you that a new record has been added to the database. To see the new record, close down your programme, and run it again. The new record will be there.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4410663255011182912/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-new-record-using-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4410663255011182912'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4410663255011182912'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-new-record-using-vb-net.html' title='Add a New Record using VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-4307342866516552098</id><published>2010-08-26T14:02:00.000-07:00</published><updated>2011-04-10T04:37:00.691-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="AddUpdate Delete Records"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Add, Update and Delete Records</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&amp;nbsp;&lt;/span&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;you learned how to move through the records in your DataSet, and how to display the records in Textboxes on your form. In this lesson, we&#39;ll see how to add new records, how to delete them and how to Update a records.&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Before we start the coding for these new buttons, it&#39;s important to understand that the DataSet is&amp;nbsp;&lt;i&gt;&lt;b&gt;disconnected&lt;/b&gt;&lt;/i&gt;&amp;nbsp;from the database. What this means is that if you&#39;re adding a new record, you&#39;re not adding it to the database: you&#39;re adding it to the&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;! Similarly, if you&#39;re updating or Deleting, you doing it to the DataSet, and&amp;nbsp;&lt;b&gt;&lt;u&gt;NOT&lt;/u&gt;&lt;/b&gt;&amp;nbsp;to the database. After you have made all of your changes, you THEN commit these changes to the database. You do this by issuing a separate command. But we&#39;ll see how it all works.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You&#39;ll need to add a few more buttons to your form - five of them. Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;properties of the new Buttons to the following:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;btnAddNew&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;btnCommit&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;btnUpdate&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;btnDelete&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;btnClear&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the&amp;nbsp;&lt;b&gt;Text&lt;/b&gt;&amp;nbsp;properties of the buttons to &quot;&lt;b&gt;Add New&lt;/b&gt;&amp;nbsp;&lt;b&gt;Record&lt;/b&gt;&amp;nbsp;&quot;, &quot;&lt;b&gt;Commit Changes&lt;/b&gt;&quot;, &quot;&lt;b&gt;Update Record&amp;nbsp;&lt;/b&gt;&quot;, &quot;&lt;b&gt;Delete&lt;/b&gt;&amp;nbsp;&lt;b&gt;Record&lt;/b&gt;&quot;, and &quot;&lt;b&gt;Clear/Cancel&lt;/b&gt;&quot;. Your form might look something like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;315&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookForm_p290.jpg&quot; width=&quot;402&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;ll start with the Update Record button&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;Updating a Record&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To reference a particular column (item) in a row of the DataSet, the code is this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(&lt;span style=&quot;color: red;&quot;&gt;2&lt;/span&gt;).&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;That will return whatever is at Item 1 on Row 2.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As well as returning a value, you can also set a value. You do it like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(&lt;span style=&quot;color: red;&quot;&gt;2&lt;/span&gt;).&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;&amp;nbsp;= &quot;Jane&quot;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now Item 1 Row 2 will contain the text &quot;Jane&quot;. This won&#39;t, however, effect the database! The changes will just get made to the&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;. To illustrate this, add the following code to your&amp;nbsp;&lt;b&gt;btnUpdate&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(1) = txtFirstName.Text&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(2) = txtSurname.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;MsgBox(&quot;Data updated&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your programme, and click the&amp;nbsp;&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button to move to the first record. &quot;John&quot; should be displayed in your first textbox, and &quot;Smith&quot; in the second textbox. Click inside the textboxes and change &quot;John&quot; to &quot;Joan&quot; and &quot;Smith&quot; to &quot;Smithy&quot;. (Without the quotes). Now click your&amp;nbsp;&lt;b&gt;Update Record&lt;/b&gt;&amp;nbsp;button. Move to the next record by clicking your&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button, and then move back to the first record. You should see that the first record is now &quot;Joan Smithy&quot;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Close down your programme, then run it again. Click the&amp;nbsp;&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button to move to the first record. It will still be &quot;John Smith&quot;. The data you updated has been lost! So here, again, is why:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&quot;Changes are made to the DataSet, and NOT to the Database&quot;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To update the database, you need some extra code. Amend your code to this (the new lines are in bold, red text):&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;Dim cb As New OleDb.OleDbCommandBuilder(da)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(1) = txtFirstName.Text&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(2) = txtSurname.Text&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;MsgBox(&quot;Data updated&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first new line is this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Dim cb As New OleDb.OleDbCommandBuilder(&lt;span style=&quot;color: blue;&quot;&gt;da&lt;/span&gt;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To update the database itself, you need something called a&amp;nbsp;&lt;b&gt;Command Builder&lt;/b&gt;. The Command Builder will build a SQL string for you. In between round brackets, you type the name of your Data Adapter,&amp;nbsp;&lt;b&gt;da&lt;/b&gt;&amp;nbsp;in our case. The command builder is then stored in a variable, which we have called&amp;nbsp;&lt;b&gt;cb&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The second new line is where the action is:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da.Update(ds, &quot;AddressBook&quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;da&lt;/b&gt;&amp;nbsp;variable is holding our Data Adapter. One of the methods of the Data Adapter is&lt;b&gt;Update&lt;/b&gt;. In between the round brackets, you need the name of your DataSet (&lt;b&gt;ds&lt;/b&gt;, for us). The &quot;&lt;b&gt;AddressBook&lt;/b&gt;&quot; part is optional. It&#39;s what we&#39;ve called our DataSet, and is here to avoid any confusion.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But the Data Adapter will then contact the database. Because we have a Command Builder, the Data Adapter can then update your database with the values from the DataSet.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Without the Command Builder, though, the Data Adapter can&#39;t do it&#39;s job. Try this. Comment out the Command Builder line (put a single quote before the &quot;D&quot; of Dim). Run your programme again, and then try and update a record. You&#39;ll get this error message:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;InvalidOperationException error&quot; height=&quot;246&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/errorAddBook_p292.jpg&quot; width=&quot;402&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The error is because you haven&#39;t got a command builder - a Valid Update Command.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Delete the comment from your Command Builder line and the error message goes away.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You should now be able to make changes to the database itself (as long as the Access database isn&#39;t Read Only).&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Try it out. Run your programme, and change one of the records. Click the&amp;nbsp;&lt;b&gt;Update&lt;/b&gt;button. Then close the programme down, and load it up again. You should see your new changes displayed in the textboxes.&lt;/div&gt;&lt;/div&gt;&lt;h3 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Exercise&lt;/div&gt;&lt;/h3&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There&#39;s one slight problem with the code above, though. Try clicking the&amp;nbsp;&lt;b&gt;Update&lt;/b&gt;&amp;nbsp;button before clicking the&amp;nbsp;&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button. What happens? Do you know why you get the error message? Write code to stop this happening&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4307342866516552098/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-update-and-delete-records.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4307342866516552098'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4307342866516552098'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/add-update-and-delete-records.html' title='Add, Update and Delete Records'/><author><name>Unknown</name><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-2315630515588192403.post-4437322784575025141</id><published>2010-08-26T14:01:00.000-07:00</published><updated>2011-04-10T04:37:00.695-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Move through  Database"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>How to Move through the Database</title><content type='html'>&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;How to Move Forward One Record at a Time&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Double click your&amp;nbsp;&lt;b&gt;Next Record&lt;/b&gt;&amp;nbsp;button to access the code. Add the following If … Else Statement:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If inc &amp;lt;&amp;gt; MaxRows - 1 Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = inc + 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;No More Rows&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re checking to see if the value in&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;does not equal the value in&amp;nbsp;&lt;b&gt;MaxRows&lt;/b&gt;&amp;nbsp;- 1. If they are both equal then we know we&#39;ve reached the last record in the DataSet. In which case, we just display a message box. If they are not equal, these two lines get executed:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = inc + 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;First, we move the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;counter on by one. Then we call the Sub we set up:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;NavigateRecords()&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Our Subroutine is where the action takes place, and the values from the DataSet are placed in the textboxes. Here it is again:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Private Sub NavigateRecords()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(1)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(2)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;End Sub&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The part that moves the record forward (and backwards soon) is this part:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Rows(&lt;span style=&quot;color: blue;&quot;&gt;inc&lt;/span&gt;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Previously, we hard-coded this with:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Rows(&lt;span style=&quot;color: blue;&quot;&gt;0&lt;/span&gt;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now the value is coming from the variable called&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;. Because we&#39;re incrementing this variable with code, the value will change each time the button is clicked. And so a different record will be displayed.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can test out your Next button. Run your programme and click the button. You should now be able to move forward through the DataSet. When you get to the end, you should see the message box display &quot;No More Rows&quot;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;None of the other button will work yet, of course. So let&#39;s move backwards.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/orderBook.html&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;font-family: Verdana, Arial, Helvetica, sans-serif;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/bookshop/net.html&quot;&gt;No more reading these lessons online - get the eBook here!&lt;/a&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Move Back One Record at a Time&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To move backwards through the DataSet, we need to decrement the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;counter. All this means is deducting 1 from whatever is currently in inc.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we also need to check that inc doesn&#39;t go past zero, which is the first record in the DataSet. Here&#39;s the code to add to your&amp;nbsp;&lt;b&gt;btnPrevious&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If inc &amp;gt; 0 Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = inc - 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;First Record&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So the If statement first checks that&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;is greater than zero. If it is, inc gets 1 deducted from. Then the NavigateRecords() subroutine gets called. If&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;is zero or less, then we display a message.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you&#39;ve finished adding the code, test your programme out. Click the Previous button first. The message box should display, even though no records have been loaded into the textboxes. This is because the variable&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;has a value of -1 when the form first loads. It only gets moved on to zero when the Next button is clicked. You could amend your IF Statement to this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If inc &amp;gt; 0 Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = inc - 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ElseIf inc = -1 Then&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;No Records Yet&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ElseIf inc = 0 Then&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;First Record&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This new If Statement now checks to see if inc is equal to minus 1, and displays a message if it does. It also checks if inc is equal to zero, and displays the &quot;First Record&quot; message box.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Moving to the Last Record in the DataSet&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To jump to the last record in the DataSet, you only need to know how many records have been loaded into the DataSet - the&amp;nbsp;&lt;b&gt;MaxRows&lt;/b&gt;&amp;nbsp;variable in our code. You can then set the&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;counter to that value, but minus 1. Here&#39;s the code to add to your&amp;nbsp;&lt;b&gt;btnLast&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If inc &amp;lt;&amp;gt; MaxRows - 1 Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = MaxRows - 1&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The reason we&#39;re saying&amp;nbsp;&lt;b&gt;MaxRows - 1&lt;/b&gt;&amp;nbsp;is that the row count might be 5, say, but the first record in the DataSet starts at zero. So the total number of records would be zero to 4. Inside of the If Statement, we&#39;re setting the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;counter to MaxRows - 1, then calling the NavigateRecords() subroutine.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;That&#39;s all we need to do. So run your programme. Click the Last button, and you should see the last record displayed in your textboxes.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Moving to the First Record in the DataSet&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Moving to the first record is fairly straightforward. We only need to set the&amp;nbsp;&lt;b&gt;inc&lt;/b&gt;&amp;nbsp;counter to zero, if it&#39;s not already at that value. Then call the Sub:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;If inc &amp;lt;&amp;gt; 0 Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;inc = 0&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;NavigateRecords()&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add the code to your&amp;nbsp;&lt;b&gt;btnFirst&lt;/b&gt;. Run your programme and test out all of your buttons. You should be able to move through the names in the database, and jump to the first and last records.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4437322784575025141/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-move-through-database.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4437322784575025141'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4437322784575025141'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-move-through-database.html' title='How to Move through the Database'/><author><name>Unknown</name><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-2315630515588192403.post-1534878697201388384</id><published>2010-08-26T14:00:00.000-07:00</published><updated>2011-04-10T04:37:00.700-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Navigate a Database"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Navigate a Database with VB .NET</title><content type='html'>&lt;table border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify; width: 791px;&quot;&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td height=&quot;398&quot; valign=&quot;top&quot;&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;you can navigate through the records of a database by incrementing or decrementing the Row number of the DataSet. In this section, we&#39;re going to see a more practical example of how to do that.To navigate through the dataset, let&#39;s change our form. By adding some navigation buttons, we can duplicate&amp;nbsp;what the wizard did. We&#39;ll also need to move the code we already have. So let&#39;s start with that.&lt;br /&gt;
At the moment, all our code is in the Button we added to the form. We&#39;re going to delete this button, so we need to move it out of there. The variable declarations can be moved right to the top of the coding window. That way, any button can see the variables. So move your variables declarations to the top, as in the image below (don&#39;t forget to add the&amp;nbsp;&lt;b&gt;Dim inc As Integer&lt;/b&gt;&amp;nbsp;line):&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td height=&quot;2472&quot; valign=&quot;top&quot;&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;142&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode_p282.jpg&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;We can move a few lines to the Form Load event. So, create a Form Load event, as you did in a previous section. Now move all but the textbox lines to there. Your coding window should then look like this (you can delete the message box lines, or just comment them out):&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img height=&quot;447&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode2_p282_B.jpg&quot; width=&quot;534&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;For your button, all you should have left are these two lines:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em; text-align: left;&quot;&gt;&lt;b&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(1)&lt;br /&gt;
txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(2)&lt;/b&gt;&lt;/div&gt;Since we&#39;re going to be deleting this button, this code can be moved. Because all the buttons need to put something into the textboxes, the two lines we have left are an ideal candidate for a Subroutine. So add the following Sub to your code:&lt;br /&gt;
&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;Private Sub NavigateRecords()&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;b&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(1)&lt;br /&gt;
txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).Rows(inc).Item(2)&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;End Sub&lt;/b&gt;&lt;/div&gt;When we navigate through the DataSet, we&#39;ll call this subroutine.&lt;br /&gt;
Now that all of your code has gone from your button, you can delete the button code altogether. Return to you form, click on the button to select it, then press the delete key on your keyboard. This will remove the button itself from your form. (You can also right click on the button, and then select Delete from the menu.)&lt;br /&gt;
Here&#39;s what your coding window should like:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img height=&quot;538&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode_p284_B.jpg&quot; width=&quot;494&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Now you can re-design the form. Add four new buttons, and change the Name properties to: btnNext, btnPrevious, btnFirst, and btnLast. Change the Text properties to &amp;gt;, &amp;lt;, &amp;lt;&amp;lt;, and &amp;gt;&amp;gt;. Your form will then look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img height=&quot;279&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookForm_p285.jpg&quot; width=&quot;329&quot; /&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;Just a couple of more things to set up before we get started. Add a new variable declaration to the top of your code, just under the Dim inc As Integer line. Add this:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;Dim MaxRows As Integer&lt;/b&gt;&lt;/div&gt;We can store how many rows are in the DataSet with this variable. You can get how many rows are in the DataSet with this:&lt;br /&gt;
&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;MaxRows = ds.Tables(&quot;AddressBook&quot;).Rows.Count&lt;/b&gt;&lt;/div&gt;So the Rows property has a Count Method. This simply counts how many rows are in the DataSet. We&#39;re passing that number to a variable called MaxRows. You can then test what is in the variable, and see if the inc counter doesn&#39;t go past it. You need to do this because VB throws up an error message if try to go past the last row in the DataSet. (Previous versions of VB had some called an EOF and BOF properties. These checked the End of File and Before End of File. These properties have now gone.)&lt;br /&gt;
Add the following two lines of code to the Form Load Event of Form1:&lt;br /&gt;
&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;MaxRows = ds.Tables(&quot;AddressBook&quot;).Rows.Count&lt;br /&gt;
inc = - 1&lt;/b&gt;&lt;/div&gt;Your code should then look like this:&lt;br /&gt;
&lt;div style=&quot;text-align: center;&quot;&gt;&lt;img height=&quot;302&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode_p286_B.jpg&quot; width=&quot;378&quot; /&gt;&lt;/div&gt;Notice the other line of code for the Form Load event:&lt;br /&gt;
&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;b&gt;inc = - 1&lt;/b&gt;&lt;/div&gt;This line sets the inc variable to minus one when the form loads. When the Buttons are clicked, this will ensure that we&#39;re moving the counter on by the correct amount.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/1534878697201388384/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/navigate-database-with-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1534878697201388384'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1534878697201388384'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/navigate-database-with-vb-net.html' title='Navigate a Database with VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-8851329228073127785</id><published>2010-08-26T13:59:00.000-07:00</published><updated>2011-04-10T04:37:00.705-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Display Data in DataSet"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Display the Data in the DataSet</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;we saw what Data Adaptors and DataSets were. We created a Data Adaptor so that it could fill a DataSet with records from our database. What we want to do now is to display the records on a Form, so that people can see them. So so this:&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add two textboxes to your form&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;properties of your textboxes to&amp;nbsp;&lt;b&gt;txtFirstName&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;txtSurname&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Go back to your code window&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add the following two lines:&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).Rows(0).Item(1)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).Rows(0).Item(2)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;You can add them after the line that closes the connection to the database. Once the DataSet has been filled, a connection to a database can be closed.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Your code should now look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;366&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode_p279_B.jpg&quot; width=&quot;431&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Before the code is explained, run your programme and click the button. You should see &quot;John Smith&quot; displayed in your two textboxes.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So let&#39;s examine the code that assigns the data from the DataSet to the textboxes. The first line was this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;txtFirstName.Text =&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;ds&lt;/span&gt;.Tables(&quot;&lt;span style=&quot;color: blue;&quot;&gt;AddressBook&lt;/span&gt;&quot;).Rows(0).Item(1)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;It&#39;s rather a long line! But after the equals sign, you type the name of your DataSet (&lt;b&gt;ds&lt;/b&gt;for us). After a full stop, select&amp;nbsp;&lt;b&gt;Tables&lt;/b&gt;&amp;nbsp;from the popup list. The&amp;nbsp;&lt;b&gt;Tables&lt;/b&gt;&amp;nbsp;property needs something in between round brackets. Quite bizarrely, this is NOT the name of your database table! It&#39;s that identifier you used with the Data Adapter Fill. We used the identifier &quot;&lt;b&gt;AddressBook&lt;/b&gt;&quot;. If we had used &quot;Bacon Sandwich&quot; then we&#39;d put this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;&lt;span style=&quot;color: blue;&quot;&gt;Bacon Sandwich&lt;/span&gt;&quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we didn&#39;t, so our code is:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;&lt;span style=&quot;color: blue;&quot;&gt;AddressBook&lt;/span&gt;&quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Type a full stop and you&#39;ll see another list popping up at you. Select&amp;nbsp;&lt;b&gt;Rows&lt;/b&gt;&amp;nbsp;from the list. In between round brackets, you need a number. This is a Row number from the DataSet. We want the first row, which is row zero in the DataSet:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).&lt;span style=&quot;color: blue;&quot;&gt;Rows(&lt;span style=&quot;color: red;&quot;&gt;0&lt;/span&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Type full stop after Rows(0) and the popup list appears again. To identify a&amp;nbsp;&lt;b&gt;Column&lt;/b&gt;from the DataSet, you use&amp;nbsp;&lt;b&gt;Item&lt;/b&gt;. In between round brackets, you type which column you want:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(0).&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In our Access database, column zero is used for an ID field. The&amp;nbsp;&lt;b&gt;FirstName&lt;/b&gt;&amp;nbsp;column is the second column in our Access database. Because the Item collection is zero based, this is item 1 in the DataSet.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can also refer to the column name itself for the Item property, rather than a number. So you can do this:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ds.Tables(&quot;AddressBook&quot;).Rows(0).&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;&quot;FirstName&quot;&lt;/span&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;ds.Tables(&quot;AddressBook&quot;).Rows(0).&lt;span style=&quot;color: blue;&quot;&gt;Item(&lt;span style=&quot;color: red;&quot;&gt;&quot;Surname&quot;&lt;/span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;If you get the name of the column wrong, then VB throws up an error. But an image might clear things up. The image below shows what the items and rows are in the database.&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;141&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBook_ACCESS_p280.jpg&quot; width=&quot;466&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The image shows which are the&amp;nbsp;&lt;b&gt;Rows&lt;/b&gt;&amp;nbsp;and which are the&amp;nbsp;&lt;b&gt;Items&lt;/b&gt;&amp;nbsp;in the Access database Table. So the&amp;nbsp;&lt;b&gt;Items&lt;/b&gt;&amp;nbsp;go down and the&amp;nbsp;&lt;b&gt;Rows&lt;/b&gt;&amp;nbsp;go across.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;However, we want to be able to scroll through the table. We want to be able to click a button and see the next record. Or click another button and see the previous record. You can do this by incrementing the Row number. To see the next record, we&#39;d want this:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).&lt;span style=&quot;color: blue;&quot;&gt;Rows(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;.Item(1)&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).&lt;span style=&quot;color: blue;&quot;&gt;Rows(&lt;span style=&quot;color: red;&quot;&gt;1&lt;/span&gt;)&lt;/span&gt;.Item(2)&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;The record after that would then be:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;txtFirstName.Text = ds.Tables(&quot;AddressBook&quot;).&lt;span style=&quot;color: blue;&quot;&gt;Rows(&lt;span style=&quot;color: red;&quot;&gt;2&lt;/span&gt;&lt;/span&gt;).Item(1)&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;txtSurname.Text = ds.Tables(&quot;AddressBook&quot;).&lt;span style=&quot;color: blue;&quot;&gt;Rows(&lt;span style=&quot;color: red;&quot;&gt;2&lt;/span&gt;)&lt;/span&gt;.Item(2)&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;So by incrementing and decrementing the Row number, you can navigate through the records. Let&#39;s see how that&#39;s done.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/8851329228073127785/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/display-data-in-dataset.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/8851329228073127785'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/8851329228073127785'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/display-data-in-dataset.html' title='Display the Data in the DataSet'/><author><name>Unknown</name><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-2315630515588192403.post-1490761227603601474</id><published>2010-08-26T13:58:00.000-07:00</published><updated>2011-04-10T04:37:00.709-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DataSets and Data Adaptors"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Learn about DataSets and Data Adaptors</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;you learned how to set up a Connection Object. This was so that you could open a connection to the database itself. But that&#39;s not the end of it. The data from the database needs to be stored somewhere, so that we can manipulate it.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;ADO.NET uses something called a&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;&amp;nbsp;to hold all of your information from the database (you can also use a DataTable, if all you want to do is read information, and not have people write to your database.). But the&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;&amp;nbsp;(and Data Table) will hold a copy of the information from the database.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The DataSet is not something you can draw on your form, like a Button or a Textbox. The DataSet is something that is hidden from you, and just stored in memory. Imagine a grid with rows and columns. Each imaginary row of the DataSet represents a Row of information in your Access database. And each imaginary column represents a Column of information in your Access database (called a Field in Access).&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This, then, is a DataSet. But what&#39;s a Data Adapter?&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Connection Object and the DataSet can&#39;t see each other. They need a go-between so that they can communicate. This go-between is called a Data Adapter. The Data Adapter contacts your Connection Object, and then executes a query that you set up. The results of that query are then stored in the DataSet.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Data Adapter and DataSet are objects. You set them up like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Dim ds As&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;New DataSet&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Dim da As OleDb.&lt;span style=&quot;color: blue;&quot;&gt;OleDbDataAdapter&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da = New OleDb.&lt;span style=&quot;color: blue;&quot;&gt;OleDbDataAdapter(&lt;/span&gt;sql, con&lt;span style=&quot;color: blue;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code needs a little explaining, though. First, the Data Adapter.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;The Data Adapter&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Data Adapter is a property of the OLEDB object, hence the full stop between the two:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;OleDb&lt;span style=&quot;color: red;&quot;&gt;.&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;OleDbDataAdapter&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;re passing this object to the variable called&amp;nbsp;&lt;b&gt;da&lt;/b&gt;. This variable will then hold a reference to the Data Adapter.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;While the second line in the code above sets up a reference to the Data Adapter, the third line creates a new Data Adapter object. You need to put two things in the round brackets of the Object declaration: Your SQL string (which we&#39;ll get to shortly), and your connection object. Our Connection Object is stored in the variable which we&#39;ve called&lt;b&gt;con&lt;/b&gt;. (Like all variable you can call it practically anything you like. We&#39;ve gone for something short and memorable.) You then pass the New Data Adapter to your variable (&lt;b&gt;da&lt;/b&gt;&amp;nbsp;for us):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da = New OleDb.&lt;span style=&quot;color: blue;&quot;&gt;OleDbDataAdapter(&lt;/span&gt;&lt;span style=&quot;color: red;&quot;&gt;sql&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;con&lt;/span&gt;&lt;span style=&quot;color: blue;&quot;&gt;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We need something else, though. The&amp;nbsp;&lt;b&gt;sql&lt;/b&gt;&amp;nbsp;in between the round brackets is the name of a variable. We haven&#39;t yet set this up. We&#39;ll have a look at SQL in a moment. But bear in mind what the Data Adaptor is doing:&amp;nbsp;&lt;b&gt;&lt;i&gt;Acting as a go-between for the Connection Object and the Data Set&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24.1667px; font-weight: bold;&quot;&gt;Structured Query Language&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;SQL (pronounced SeeKwel), is short for Structured Query Language, and is a way to query and write to databases (not just Access). The basics are quite easy to learn. If you want to grab all of the records from a table in a database, you use the SELECT word. Like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;SELECT * FROM Table_Name&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;SQL is not case sensitive, so the above line could be written:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Select * from Table_Name&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But your SQL statements are easier to read if you type the keywords in uppercase letters. The keywords in the lines above are&amp;nbsp;&lt;b&gt;SELECT&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;FROM&lt;/b&gt;. The asterisk means &quot;All Records&quot;. Table_Name is the name of a table in your database. So the whole line reads:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&quot;SELECT all the records FROM the table called Table_Name&quot;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You don&#39;t need to select all (*) the records from your database. You can just select the columns that you need. The name of the table in our database is&amp;nbsp;&lt;b&gt;tblContacts&lt;/b&gt;. If we wanted to select just the first name and surname columns from this table, we can specify that in our SQL String:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;SELECT&lt;/span&gt;&amp;nbsp;tblContacts.FirstName, tblContacts.Surname&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;FROM&lt;/span&gt;&amp;nbsp;tblContacts&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When this SQL statement is executed, only the FirstName and Surname columns from the database will be returned.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are a lot more SQL commands, but for our purposes this is enough.&amp;nbsp;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Because we want to SELECT all (*) the records from the table called tblContacts, we pass this string to the string variable we have called sql:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;sql = &quot;SELECT * FROM tblContacts&quot;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Your code window should now look like this (though the file path to your database might be different):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;424&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/addressBookCode_p278.jpg&quot; width=&quot;429&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now that the Data Adapter has selected all of the records from the table in our database, we need somewhere to put those records - in the&amp;nbsp;&lt;b&gt;DataSet&lt;/b&gt;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/orderBook.html&quot;&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Filling the DataSet&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Data Adapter can Fill a DataSet with records from a Table. You only need a single line of code to do this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;da&lt;/span&gt;.Fill(ds, &quot;AddressBook&quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As soon as you type the name of your Data Adapter (&lt;b&gt;da&lt;/b&gt;&amp;nbsp;for us), you&#39;ll get a pop up box of properties and methods. Select Fill from the list, then type a pair of round brackets. In between the round brackets, you need two things: the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;of your DataSet (&lt;b&gt;ds&lt;/b&gt;, in our case), and an identifying name. This identifying name can be anything you like. But it is just used to identify this particular Data Adapter Fill. We could have called it &quot;Bacon Sandwich&quot;, if we wanted:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da.Fill(ds, &quot;Bacon Sandwich &quot;)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code above still works. But it&#39;s better to stick to something a little more descriptive than &quot;Bacon Sandwich&quot;!&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add the new line after the creation of the Data Adaptor:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;da = New OleDb.OleDbDataAdapter(sql, con)&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;da.Fill(ds, &quot;AddressBook&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And that&#39;s it. The DataSet (&lt;b&gt;ds&lt;/b&gt;) will now be filled with the records we selected from the table called&amp;nbsp;&lt;b&gt;tblContact&lt;/b&gt;. There&#39;s only one slight problem - nobody can see the data yet! We&#39;ll tackle that in the next part.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/1490761227603601474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/learn-about-datasets-and-data-adaptors.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1490761227603601474'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1490761227603601474'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/learn-about-datasets-and-data-adaptors.html' title='Learn about DataSets and Data Adaptors'/><author><name>Unknown</name><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-2315630515588192403.post-2405648499054580136</id><published>2010-08-26T13:57:00.000-07:00</published><updated>2011-04-10T04:37:00.714-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB .NET database code"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Write your own VB .NET database code</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In this next section, we&#39;ll take a look at the objects that you can use to open and read data from a Database. We&#39;ll stick with our Access database, the AddressBook.mdb one, and recreate what the Wizard has done. That way, you&#39;ll see for yourself just what is going on behind the scenes.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So close any open projects, and create a new one. Give it whatever name you like, and let&#39;s begin.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you haven&#39;t yet downloaded the Address Book database, you can get it here:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/net/AddressBook.zip&quot;&gt;&lt;b&gt;Download the Address Book Database&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;&amp;nbsp;The Connection Object&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Connection Object is what you need if you want to connect to a database. There are a number of different connection objects, and the one you use depends largely on the type of database you&#39;re connecting to. Because we&#39;re connecting to an Access database, we&#39;ll need something called the OLE DB connection object.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;OLE stands for Object Linking and Embedding, and its basically a lot of objects (COM objects) bundled together that allow you to connect to data sources in general, and not just databases. You can use it, for example, to connect to text files, SQL Server, email, and a whole lot more.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are a number of different OLE DB objects (called data providers), but the one we&#39;ll use is called &quot;&lt;b&gt;Jet&lt;/b&gt;&quot;. Others are SQL Server and Oracle.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So place a button on your form. Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;property to&amp;nbsp;&lt;b&gt;btnLoad&lt;/b&gt;. Double click your button to open up the code window. Add the following line:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Dim con As New&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;OleDb.OleDbConnection&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The variable&amp;nbsp;&lt;b&gt;con&lt;/b&gt;&amp;nbsp;will now hold the&amp;nbsp;&lt;b&gt;Connection Objec&lt;/b&gt;t. Notice that there is a full stop after the OleDB part. You&#39;ll then get a pop up box from where you can select OleDbConnection. We&#39;re also creating a&amp;nbsp;&lt;b&gt;New&lt;/b&gt;&amp;nbsp;object on this line.This is the object that you use to connect to an Access database.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24px; font-weight: bold;&quot;&gt;Setting a Connection String&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;There are Properties and Methods associated with the Connection Object, of course. We want to start with the ConnectionString property. This can take MANY parameters . Fortunately, we only need a few of these.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We need to pass two things to our new&amp;nbsp;&lt;b&gt;Connection Object&lt;/b&gt;: the technology we want to use to do the connecting to our database; and where the database is. (If your database was password and user name protected, you would add these two parameters as well. Ours isn&#39;t, so we only need the two.)&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The technology is called the&amp;nbsp;&lt;b&gt;Provider&lt;/b&gt;; and you use&amp;nbsp;&lt;b&gt;Data Source&lt;/b&gt;&amp;nbsp;to specify where your database is. So add this to your code:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Dim dbProvider As String&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;Dim dbSource As String&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;dbProvider = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;&quot;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;dbSource = &quot;Data Source = C:/AddressBook.mdb&quot;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;con.ConnectionString = dbProvider &amp;amp; dbSource&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first part specifies which provider technology we want to use to do the connecting (JET). The second part, typed after a semi-colon, points to where the database is. In the above code, the database is on the C drive, in the root folder. The name of the Access file we want to connect to is called AddressBook.mdb. (Note that &quot;Data Source&quot; is two words, and not one.)&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you prefer, you can have the provider and source on one line, as below (it&#39;s on two here because it won&#39;t all fit on one line):&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;con.ConnectionString = &quot;PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\AddressBook.mdb&quot;&amp;nbsp;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first part specifies which provider technology we want to use to do the connecting (&lt;b&gt;JET&lt;/b&gt;). The second part, typed after a semi-colon, points to where the database is. In the above code, the database is on the C drive, in the root folder. The name of the Access file we want to connect to is called&amp;nbsp;&lt;b&gt;AddressBook.mdb.&lt;/b&gt;&amp;nbsp;(Note that &quot;&lt;b&gt;Data Source&lt;/b&gt;&quot; is two words, and not one.)&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But your coding window should now look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;262&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/db_con1.gif&quot; width=&quot;475&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This assumes that you have copied the AddressBook database over to the root folder of your C Drive. If you&#39;ve copied it to another folder, change the &quot;Data Source&quot; part to match. For example, if you copied it to a folder called &quot;databases&quot; you&#39;d put this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Data Source = C:\databases\AddressBook.mdb&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can also specify a folder such as MyDocuments (or Documents in Vista and Windows 7). You do it like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;dbSource = &quot;Data Source = C:\Users\Owner\Documents\AddressBook.mdb&quot;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Another way to specify a file path is this:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Dim fldr As String&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;fldr = Environment.GetFolderPath( Environment.SpecialFolder.MyDocuments ) &amp;amp; &quot;/AddressBook.mdb&quot;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;dbSource = &quot;Data Source = &quot; &amp;amp; fldr&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;On the second line, spread over two lines in the code above, we have this:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Environment.GetFolderPath( )&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The folder path you&#39;re getting goes between the round brackets of GetFolderPath:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Environment.SpecialFolder.MyDocuments&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Special Folder in this case is the MyDocuments folder.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But back to our connection code.&amp;nbsp;&lt;b&gt;ConnectionString&lt;/b&gt;&amp;nbsp;is a property of the&amp;nbsp;&lt;b&gt;con&lt;/b&gt;&amp;nbsp;variable. The con variable holds our Connection Object. We&#39;re passing the Connection String the name of a data provider, and a path to the database.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Opening the Connection&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now that we have a ConnectionString, we can go ahead and open the datatbase. This is quite easy - just use the&amp;nbsp;&lt;b&gt;Open&lt;/b&gt;&amp;nbsp;method of the Connection Object:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;con.Open( )&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once open, the connection has to be closed again. This time, just use the Close method:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;con.Close( )&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add the following four lines to your code:&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;con.Open()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;MsgBox(&quot;Database is now open&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;con.Close()&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox(&quot;Database is now Closed&quot;)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Your coding window will then look like this (use the file path below, if you have Vista or Windows 7, after moving the database to your Documents folder):&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;362&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/db_con2.gif&quot; width=&quot;509&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Test out your new code by running your programme. Click your button and the two message boxes should display. If they don&#39;t, make sure your Data Source path is correct. If it isn&#39;t, you might see this error message:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;OleDbException Error&quot; height=&quot;233&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/errorAddBook_p275.jpg&quot; width=&quot;402&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The error message is a bit on the vague and mysterious side. But what it&#39;s saying is that it can&#39;t find the path to the database, so it can&#39;t Open the connection. The line con.Open in your code will then be highlighted in green. You need to specify the correct path to your database. When you do, you&#39;ll see the message boxes from our code, and not the big one above.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now that we&#39;ve opened a connection to the database, we need to read the information from it. This is where the DataSet and the DataAdapter come in.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/2405648499054580136/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/write-your-own-vb-net-database-code.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2405648499054580136'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/2405648499054580136'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/write-your-own-vb-net-database-code.html' title='Write your own VB .NET database code'/><author><name>Unknown</name><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-2315630515588192403.post-44599691951189736</id><published>2010-08-26T13:56:00.000-07:00</published><updated>2011-04-10T04:37:00.719-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Database Wizard"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>The Database Wizard in VB NET Express</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Let&#39;s make a start on our Database project. So, once you have your VB software open, do the following:&lt;/div&gt;&lt;ul&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click&amp;nbsp;&lt;b&gt;File &amp;gt; New Project&lt;/b&gt;&amp;nbsp;from the menu bar&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Select&amp;nbsp;&lt;b&gt;Windows Application&lt;/b&gt;, and then give it the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;AddressBook. Click OK&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Locate the&amp;nbsp;&lt;b&gt;Solution Explorer&amp;nbsp;&lt;/b&gt;on the right hand side (If you can&#39;t see it, click&lt;b&gt;View &amp;gt; Solution Explorer&lt;/b&gt;&amp;nbsp;from the menu bar, or&amp;nbsp;&lt;b&gt;View &amp;gt; Other Windows &amp;gt; Solution Explorer&lt;/b&gt;&amp;nbsp;in version 2010.)&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Solution Explorer&quot; border=&quot;1&quot; height=&quot;187&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/dbWizardED.jpg&quot; width=&quot;266&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;We need to select a Data Source. So click on&amp;nbsp;&lt;b&gt;Data Sources&lt;/b&gt;&amp;nbsp;at the bottom of the Solution Explorer in version 2008:&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Select the Data Source tab&quot; border=&quot;1&quot; height=&quot;190&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/dbWizardED2.jpg&quot; width=&quot;266&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you have VB NET 2010 then the Data Source tab is on the left, just below the Toolbox:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Data Source tab in  VB Net 2010&quot; height=&quot;179&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dataSource_A.gif&quot; width=&quot;27&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To Add a New Data Source, click on the link. When you do, you&#39;ll see a screen welcoming you to the Data Source Configuration Wizard, Just click Next, to get to the screen below:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Data Source Configuration Wizard - Step One&quot; height=&quot;385&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep1.jpg&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You want to connect to a Database. So select this option, and click Next. In version 2010 of VBN NET, you&#39;ll see this screen appear (you won&#39;t see it if you have version 2008):&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Choose a Database Model&quot; height=&quot;357&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dataSource_wizard_A.gif&quot; width=&quot;464&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Select DataSet and click Next.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In both versions 2008 and 2010, you&#39;ll then see this screen:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Data Source Configuration Wizard - Step Two&quot; height=&quot;385&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep2.jpg&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the&amp;nbsp;&lt;b&gt;New Connection&lt;/b&gt;&amp;nbsp;button and another dialogue box pops up:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Adding a connection&quot; height=&quot;405&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep3.jpg&quot; width=&quot;332&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the&amp;nbsp;&lt;b&gt;Change&lt;/b&gt;&amp;nbsp;button, because we want to connect to an Access database. (The default is for a SQL Server database.) When you click&amp;nbsp;&lt;b&gt;Change&lt;/b&gt;, you&#39;ll see this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Change the data source to an Access Database&quot; height=&quot;257&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep4.jpg&quot; width=&quot;438&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Select&amp;nbsp;&lt;b&gt;Microsoft Access Database File&lt;/b&gt;, then click OK. The previous dialogue box will then look like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Browse for a database file&quot; height=&quot;362&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep5.jpg&quot; width=&quot;332&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the&amp;nbsp;&lt;b&gt;Browse&lt;/b&gt;&amp;nbsp;button and navigate to where on your computer you downloaded our Access Database called AddressBook.mdb. Click&amp;nbsp;&lt;b&gt;Test Connection&lt;/b&gt;&amp;nbsp;to see if everything is OK, and you&#39;ll hopefully see this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Test the connection&quot; border=&quot;1&quot; height=&quot;165&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/db_test_connection.gif&quot; width=&quot;256&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the OK button, then click the OK button on the Add Connection dialogue box as well. You will be returned to the Data Source Configuration Wizard, which should now look like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Datrabase file is now selected&quot; height=&quot;385&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep7.jpg&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click Next to move to the next step of the Wizard. You may see a message box appear, however. Click No on the message box to stop VB copying the database each time it runs. You should then see this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Save the connection string&quot; height=&quot;285&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep8.jpg&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Make sure there&#39;s a tick in the box for &quot;Save the connection&quot;, and then click Next:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The database objects&quot; height=&quot;455&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbStep9.jpg&quot; width=&quot;500&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Here, you can select which tables and fields you want. Tick the&amp;nbsp;&lt;b&gt;Tables&lt;/b&gt;&amp;nbsp;box to include them all. You can give your DataSet a name, if you prefer. Click Finish and you&#39;re done.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you are returned to your form, you should notice the Solution Explorer has added your new Data Source:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The data source tab&quot; height=&quot;176&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbDataSource2.jpg&quot; width=&quot;252&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Data Sources area of the Solution Explorer now displays information about your database. Click the plus symbol (an arrow in VB NET 2010) next to&amp;nbsp;&lt;b&gt;tblContacts&lt;/b&gt;:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The database fields&quot; border=&quot;1&quot; height=&quot;280&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbDataSource3.jpg&quot; width=&quot;252&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;All the Fields in the Address Book database are now showing.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To add a Field to your Form, click on one in the list. Hold down your left mouse button, and drag it over to your form:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Drag a database field to the form&quot; height=&quot;254&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbDataSource4.jpg&quot; width=&quot;252&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the image above, the&amp;nbsp;&lt;b&gt;FName&lt;/b&gt;&amp;nbsp;field is being dragged on the Form. Your mouse cursor will change shape.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When your Field is over the Form, let go of your left mouse button. A textbox and a label will be added. There are two other things to notice: a navigation bar appears at the top of the form, and a lot of strange objects have appeared in the object area at the bottom:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Database objects on a VB NET form&quot; border=&quot;1&quot; height=&quot;401&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbForm.jpg&quot; width=&quot;336&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;ll explore the Objects in a later section. But notice the Navigation bar in blue. Run your programme by hitting the F5 key on your keyboard. You should see this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The database form running&quot; height=&quot;300&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbForm4.jpg&quot; width=&quot;300&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the Navigation arrows to scroll through the database. When you&#39;ve played around with the controls, stop the form from running, and return to Design View.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Drag and Drop more Fields to your form. But don&#39;t align them yet. We&#39;ll see an easy way to do this. But once you&#39;ve dragged the fields to your form, it might look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;439&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbForm3.jpg&quot; width=&quot;422&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;I&#39;m sure you&#39;ll agree - that&#39;s a very untidy form. But there&#39;s a very easy way to align all your controls. Try this:&lt;/div&gt;&lt;/div&gt;&lt;ul&gt;&lt;li style=&quot;text-align: justify;&quot;&gt;Click on a Textbox and its label with your left mouse button&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;Hold down the Ctrl key on your keyboard, and select a second Textbox and label&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;With the Ctrl key still held down, click each Textbox and label in turn&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;When all Textbox are selected, click on the&amp;nbsp;&lt;b&gt;Format&lt;/b&gt;&amp;nbsp;menu at the top&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;From the Format menu select&amp;nbsp;&lt;b&gt;Align &amp;gt; Lefts&lt;/b&gt;. The left edges of the Textboxes will align themselves&lt;/li&gt;
&lt;li style=&quot;text-align: justify;&quot;&gt;From the Format menu select&amp;nbsp;&lt;b&gt;Vertical Spacing &amp;gt; Make Equa&lt;/b&gt;l. The space between each textbox will then be the same&lt;/li&gt;
&lt;/ul&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;With your new controls added, and nicely aligned, press F5 to run your form. For the Notes Textbox, set the MultiLine property to True. Your form might then be something like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The finished database project&quot; height=&quot;426&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbForm5.jpg&quot; width=&quot;407&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click the Navigation icons to move backwards and forwards through your database.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In the next part, you&#39;ll move away from the Wizards and learn how to add your own programming code to open up and manipulate databases.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/44599691951189736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/database-wizard-in-vb-net-express.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/44599691951189736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/44599691951189736'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/database-wizard-in-vb-net-express.html' title='The Database Wizard in VB NET Express'/><author><name>Unknown</name><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-2315630515588192403.post-5032180916119509437</id><published>2010-08-26T13:54:00.000-07:00</published><updated>2011-04-10T04:37:00.723-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="VB  Express and Databases"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>VB NET Express and Databases</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;For this tutorial, we&#39;re going to create a simple Address Book project. The names and addresses will come from a Microsoft Access database. Download the database before starting these lessons. Once you have saved the database to your own computer, you can begin.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/net/AddressBook.zip&quot;&gt;Download the Microsoft Access Database you need for these tutorials&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;VB.Net allows you many ways to connect to a database or a data source. The technology used to interact with a database or data source is called ADO.NET. The ADO parts stands for Active Data Objects which, admittedly, doesn’t explain much. But just like System was a Base Class (leader of a hierarchy, if you like), so is ADO. Forming the foundation of the ADO Base Class are five other major objects:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Connection&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;Command&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;DataReader&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;DataSet&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;DataAdapter&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We’ll see just what these objects are, and how to use them, in a later section. But we can make a start on the ADO.NET trail by creating a simple Address Book project. All we’ll do is see how to use ADO to open up the database you downloaded, and scroll through each entry.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;What we’re going to be doing is to use a Wizard to create a programme that reads the database and allows us to scroll through it. The wizard will do most of the work for us, and create the controls that allow users to move through the database. The Form we create will look like this when it&#39;s finished:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img height=&quot;426&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/vb_2010/dbForm5.jpg&quot; width=&quot;407&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/5032180916119509437/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/vb-net-express-and-databases.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/5032180916119509437'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/5032180916119509437'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/vb-net-express-and-databases.html' title='VB NET Express and Databases'/><author><name>Unknown</name><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-2315630515588192403.post-1497894328344192804</id><published>2010-08-26T13:53:00.000-07:00</published><updated>2011-04-10T04:37:00.727-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Use your New Property"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>How to Use your New Property</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;he property you have just created is not much good where it is. You need to be able to call it into action. The way you do that is to create a new object from the Class, and then read and write to your property.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So double click the new button you added to your form. Add the following code to it:&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim&amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;objAlterPicBox&lt;/span&gt;&amp;nbsp;As&lt;span style=&quot;color: black;&quot;&gt;changeHeightWidth&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Dim&amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;NewHeight&lt;/span&gt;&amp;nbsp;As&amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;Integer&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span style=&quot;color: black;&quot;&gt;objAlterPicBox&lt;/span&gt;&amp;nbsp;= New&amp;nbsp;&lt;span style=&quot;color: black;&quot;&gt;changeHeightWidth&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Two of the line you&#39;ve already met: the one that creates a pointer to a variable (the first line), and the one that creates a new Object from your Class (the third line). The second line just sets up a variable called NewHeight.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To pass a value to your new Property (the Set part), add this line:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;objAlterPicBox.ChangeHeight = Val(txtHeight.Text)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As soon as you type the name of your object variable, then a full stop, you&#39;ll see the pop up box appear:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Your new Property is on the list&quot; height=&quot;159&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/addClassProps2.gif&quot; width=&quot;363&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The image above is from the VB NET Express edition. Other users may see a different image. But your property will still be on the list. (You can tell it&#39;s a Property because the symbol next to it is a hand holding a card.) If you double click the Property, the code is added for you.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After typing an equals sign, you then assign a value to your new property. Here, we&#39;re just passing the property whatever value is inside of the textbox called txtHeight.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we need to Get a value back out, so that we can do something with it. The way you Get at values is to put your code that accesses the property on the right hand side of an equals sign. On the left, You need the name of a variable.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So add the following to your code:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;NewHeight = objAlterPicBox.ChangeHeight&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So whatever value was stored inside of&amp;nbsp;&lt;b&gt;ChangeHeight&lt;/b&gt;&amp;nbsp;(or Returned),&amp;nbsp;&lt;b&gt;Gets&lt;/b&gt;&amp;nbsp;handed over to the&amp;nbsp;&lt;b&gt;NewHeight&lt;/b&gt;&amp;nbsp;variable.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can then set the height of the picture box:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;PictureBox1.Height = NewHeight&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you add that line above, your Button code should look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img border=&quot;1&quot; height=&quot;261&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/classCode_p245.gif&quot; width=&quot;430&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Notice the last line:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;objAlterPicBox =&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;Nothing&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Because objects take up space in memory, you can release them by setting the object to Nothing. VB is supposed to do the cleaning up for you, but you can&#39;t be sure that it&#39;s doing its job properly. So it&#39;s good form to release your own objects from memory.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you&#39;ve finished adding the code, run your programme and test it out. Click your new button and the Height of the picture box should change.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So just to recap:&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You set up a Property by using the following code stub:&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;Public Property PropertyName( ) As VaraibleType&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Get&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;br /&gt;
&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Get&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Set(ByVal Value As Integer)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;End Set&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End Property&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;Set&lt;/b&gt;&amp;nbsp;Statement is for setting values for your properties&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The&amp;nbsp;&lt;b&gt;Get&lt;/b&gt;&amp;nbsp;Statement is for returning values from your properties&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once you’ve created a new object variable to use you class, type the name of the variable and select your property from the pop up list&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you’re setting values for your property, the object variable and property go on the left hand side of the equals sign&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;ObjectVariableName&lt;/b&gt;&lt;/span&gt;&lt;b&gt;.&lt;span style=&quot;color: blue;&quot;&gt;PropertyName&lt;/span&gt;&amp;nbsp;= PropertyValue&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you’re getting values from your property, the object variable and property go on the right hand side of the equals sign&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;VariableName =&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;ObjectVariableName.PropertyName&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Release your objects from memory by using the Nothing keyword&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;OK, that’s just about it for this introduction to Classes and Objects. There’s an awful lot more to learn about Objects, but as a beginner you have learned the fundamentals.. Before you leave this topic, try this exercise:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;h3 style=&quot;text-align: justify;&quot;&gt;Exercise&lt;/h3&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Set up a property that changes the width of the Picture Box on your Form. Get the new width from the second textbox on your Form.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/1497894328344192804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-use-your-new-property.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1497894328344192804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/1497894328344192804'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-use-your-new-property.html' title='How to Use your New Property'/><author><name>Unknown</name><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-2315630515588192403.post-4234580133028023396</id><published>2010-08-26T13:52:00.000-07:00</published><updated>2011-04-10T04:37:00.731-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Create Properties in Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Create Properties in your Classes</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;h2 style=&quot;text-align: justify;&quot;&gt;Creating your own Properties in VB .NET Classes&lt;/h2&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can add your own Properties to your Class. A Property, remember, is something that changes or sets a value. Examples are, setting the Text in a textbox, changing the background colour of a Form, and setting a Button to be Enabled.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can Get values from a Property or Set them. So for a Textbox, you can Set the text to appear in the textbox, or you can Get what text is inside of the textbox. You use these same words, Get and Set, when you&#39;re creating your own Properties. An example might clear things up.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In this example, we&#39;ll allow users to set the height and width of an image. These values will come from textboxes on a form. Before you do the following, download the image you will need for this tutorial:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;a href=&quot;http://www.homeandlearn.co.uk/net/images/planet.zip&quot;&gt;&lt;b&gt;Download the image for these tutorials (WinZip file)&lt;/b&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once you have the images on your hard drive, do the following:&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Start a new project&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add a Picture Box control to your Form&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Set the&amp;nbsp;&lt;b&gt;SizeMode&lt;/b&gt;&amp;nbsp;Property of the Picture box to&amp;nbsp;&lt;b&gt;StretchImage&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Click on the&amp;nbsp;&lt;b&gt;Image&lt;/b&gt;&amp;nbsp;Property, and add the&amp;nbsp;&lt;b&gt;planet.jpg&lt;/b&gt;&amp;nbsp;image that you downloaded above&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add two textboxes to the form. Change the Name of the first one to&amp;nbsp;&lt;b&gt;txtHeight&lt;/b&gt;, and the second one to&amp;nbsp;&lt;b&gt;txtWidth&lt;/b&gt;. Enter&amp;nbsp;&lt;b&gt;300&lt;/b&gt;&amp;nbsp;as a the text for both textboxes&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add two labels to the form. Set the&amp;nbsp;&lt;b&gt;Text&lt;/b&gt;&amp;nbsp;of the first one to&amp;nbsp;&lt;b&gt;Height&lt;/b&gt;, and the second one to&amp;nbsp;&lt;b&gt;Width&lt;/b&gt;. Move them next to the textboxes&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add a new button to your form. Set the&amp;nbsp;&lt;b&gt;Text&lt;/b&gt;&amp;nbsp;property to “Change Height and Width”&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You now need to add a new class. So from the menu bar, click&amp;nbsp;&lt;b&gt;Project&lt;/b&gt;. From the&lt;b&gt;Project&lt;/b&gt;&amp;nbsp;menu, select&amp;nbsp;&lt;b&gt;Add Class&lt;/b&gt;. Give it the Name of&amp;nbsp;&lt;b&gt;changeHeightWidth.vb&lt;/b&gt;. Click the&amp;nbsp;&lt;b&gt;Add&lt;/b&gt;&amp;nbsp;button, and you&#39;ll be taken to the coding window for your new Class.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;VB now needs to know that you want to set up a Property for your Class. The way you do this is type &quot;&lt;b&gt;Public Property … End Property&lt;/b&gt;&quot;.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;On a new line, and before&amp;nbsp;&lt;b&gt;End Class&lt;/b&gt;, type the following:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Public Property ChangeHeight() As Integer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;ChangeHeight&lt;/b&gt;&amp;nbsp;is the name of our property, and it&#39;s something we made up ourselves. After a pair of round brackets, you add the type of value that will be returned (Just like a function). Here, we want to return an Integer value.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you press the return key after typing that line, VB finishes off the rest of the code stub for you:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Public Property ChangeHeight() As Integer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Get&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Get&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Set(ByVal Value As Integer)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Set&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Property&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Before the code is explained, add a new variable right at the top of your code, just below &quot;Public Class changeHeightWidth&quot;. Add this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Private intHeight As Integer&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Private word means that only code inside of the Class can see this variable. You can&#39;t access this code directly from a button on a Form, for example.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The reason the variable is right at the top is so that other chunks of code can see and use it.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But your coding window should now look something like this next image:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The code for your Class&quot; border=&quot;1&quot; height=&quot;425&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddClassProps.gif&quot; width=&quot;463&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;With the&amp;nbsp;&lt;b&gt;Get&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;Set&lt;/b&gt;&amp;nbsp;parts, the Property stub is this:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Public Property PropertyName( ) As VaraibleType&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Property&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The reason the&amp;nbsp;&lt;b&gt;Get&lt;/b&gt;&amp;nbsp;and&amp;nbsp;&lt;b&gt;Set&lt;/b&gt;&amp;nbsp;are there is so that you can Set a value for your property, and get a value back out.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To Set a value, the code inside of Property is this:&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;Set(ByVal Value As Integer)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;End Set&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Set word is followed by a pair of round brackets. Inside of the round brackets is&lt;b&gt;ByVal Value As Integer&lt;/b&gt;. The is just like a Sub, when you hand over a value to it. The name of the variable,&amp;nbsp;&lt;b&gt;Value&lt;/b&gt;, is a default name. You can change this to anything you like. The type of variable,&amp;nbsp;&lt;b&gt;As Integer&lt;/b&gt;, is also a default. You don&#39;t have to pass numbers to you property. If you want your Property to handle text you might have something like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Set(&lt;span style=&quot;color: blue;&quot;&gt;ByVal MyText As String&lt;/span&gt;)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But you couldn&#39;t do this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Set(&lt;span style=&quot;color: blue;&quot;&gt;ByVal Value As Integer&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;ByVal MyString As String&lt;/span&gt;)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In other words, you can&#39;t pass two values to your property. You can only pass one value.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we want to pass a number to our property. For us, this value will come from the textbox on the form. Whatever number is inside of the textbox will get handed over to our Property.&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;Set(ByVal&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;Value&lt;/span&gt;&amp;nbsp;As Integer)&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But we need to use this value being handed over. We can assign it to that variable we set up at the top of the Class. So add this to your code (The new line is in bold):&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: blue;&quot;&gt;Set(ByVal&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;Value&lt;/span&gt;&amp;nbsp;As Integer)&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;intHeight =&amp;nbsp;&lt;span style=&quot;color: red;&quot;&gt;Value&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;End Set&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;Whenever our Property is called into action, we&#39;re setting a&amp;nbsp;&lt;b&gt;Value&lt;/b&gt;, and then handing that value to a variable called&amp;nbsp;&lt;b&gt;intHeight&lt;/b&gt;. This is known as Writing to a Property.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To read from a Property, you use Get. This will Get a value back out of your Property. The code stub is this:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Get&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;End Get&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You don&#39;t need any round brackets for the Get part. You&#39;re just fetching something to be read.&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add the line in bold text to your Get statement.&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Get&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;ChangeHeight = intHeight&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End Get&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;All you&#39;re doing here is returning a value, just like you do with a function. You&#39;re handing a value to whatever name you called your property. We called ours&amp;nbsp;&lt;b&gt;ChangeHeight&lt;/b&gt;. It&#39;s an Integer. So we can pass whatever value was stored inside of&amp;nbsp;&lt;b&gt;intHeight&lt;/b&gt;&amp;nbsp;over to the variable called&amp;nbsp;&lt;b&gt;ChangeHeight&lt;/b&gt;:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;ChangeHeight = intHeight&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can also use the Return keyword. Like this:&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;Get&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Return intHeight&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;End Get&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Let&#39;s see how to use our new Property. (It&#39;s not a terribly useful property, by the way. A Picture box already has a Height and Width property that you can use. So ours is a bit redundant. But we&#39;re keeping it simple so that you can understand how to create your own properties.)&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4234580133028023396/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/create-properties-in-your-classes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4234580133028023396'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4234580133028023396'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/create-properties-in-your-classes.html' title='Create Properties in your Classes'/><author><name>Unknown</name><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-2315630515588192403.post-4527647310759988173</id><published>2010-08-26T13:51:00.000-07:00</published><updated>2011-04-10T04:37:00.736-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Creating Methods"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>More about Creating Methods</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In&amp;nbsp;the last part, you created a Method that returned a value. But you Methods do not have to return a value. In which case, you create a Sub and not a Function, like we did&amp;nbsp;the last time. Add the following code to your Class:&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Public Sub DoMessageBox()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent3&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;MsgBox(&quot;Conversion Complete&quot;)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;End Sub&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This is a Public Sub that doesn&#39;t do anything terribly useful. But it will illustrate how to write code to set up a Method that doesn&#39;t return a value. Here&#39;s what your coding window should look like:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;A Function and a Sub have been added to the Class&quot; border=&quot;1&quot; height=&quot;253&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddModuleSub3.gif&quot; width=&quot;467&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To run your new method, return to your Button code. You should have this, remember:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The code for your Button&quot; border=&quot;1&quot; height=&quot;217&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddClassButtonCode.gif&quot; width=&quot;429&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;On a new line after&amp;nbsp;&lt;b&gt;Textbox1.Text = NewCode&lt;/b&gt;, type the following:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;objConvertPostcode.DoMessageBox()&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After you type the name of your Object variable, then a full stop, you get the message box popping up. This time, your new Method is on the list:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Our new Method is on the list!&quot; height=&quot;143&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddClassMethodSub.gif&quot; width=&quot;291&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The tip next to the pop up box is telling you that the Method is a Sub, and that it therefore doesn&#39;t return a value. The Sub also has no parameters inside of the round brackets, so you don&#39;t have to hand anything to it.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can double click the new Method to add it to your code. When you press the return key on your keyboard, VB adds a pair of round brackets to the end of the line.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So calling a Method that doesn&#39;t return a value is just like calling a Sub. The difference is that you need the name of your Object variable first. If we had set up the Sub inside of the Form1 code, we would have just done this to call it:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;DoMessageBox()&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But because the Sub was inside of the Class, you first type the name of your Object variable:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;objConvertPostcode&lt;/span&gt;.DoMessageBox()&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your code again. Click your button. You should see two things happen: one, the text in the textbox will change; and two, you should see message box popping up confirming the change.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4527647310759988173/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/more-about-creating-methods.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4527647310759988173'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4527647310759988173'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/more-about-creating-methods.html' title='More about Creating Methods'/><author><name>Unknown</name><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-2315630515588192403.post-7238308725542793220</id><published>2010-08-26T13:50:00.000-07:00</published><updated>2011-04-10T04:37:00.741-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Create Methods in Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>How to Create Methods in your Classes</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A method created in a Class is nothing more that a Function or a Sub. You&#39;ve seen how to do this in an&amp;nbsp;earlier section. The process is the same. So add the following code to the Class you created for&amp;nbsp;the previous lesson:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Public Function DoConvert(ByVal postcode As String) As String&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Dim ConvertPostcode As String&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;ConvertPostcode = StrConv(postcode, VbStrConv.UpperCase)&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;DoConvert = ConvertPostcode&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;End Function&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you&#39;ve finished typing it all, you Class should look like this in the code window:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Function inside of your class&quot; border=&quot;1&quot; height=&quot;161&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddModuleMethod.gif&quot; width=&quot;467&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;All we&#39;ve done is to set up a Public (not private) function. We&#39;ve given it the name &quot;DoConvert&quot;. We&#39;ve set it up to accept one parameter, a String variable called postcode. This is the value that will be handed to our function. The function itself has been set up as a String. This means that DoConvert will be just like a string variable that we can assign a value to.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The code itself you&#39;ve met before. It uses the in-built StrConv function to do the actual job of converting the string to uppercase letters.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Now that we&#39;ve set up a Method, let&#39;s see how to create an object from our Class, and put the Method to use.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-size: 24.1667px; font-weight: bold;&quot;&gt;Creating an Object from a Class&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Our function is not much use until we can get it up and running. (Here, &quot;Get it up and running&quot; means create an object from our class.) To do that, double click the button on your Form, and add the following code to it:&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;b&gt;Dim NewCode As String&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Dim objConvertPostcode As ConvertPostcode&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;objConvertPostcode = New ConvertPostcode&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/b&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;NewCode = objConvertPostcode.DoConvert(TextBox1.Text)&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class=&quot;TextIndent2&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;TextBox1.Text = NewCode&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The first line just sets up a new String variable called NewCode. Whatever is returned from our function will be stored inside of this variable.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next line is where the action starts:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Dim objConvertPostcode As ConvertPostcode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The variable name&amp;nbsp;&lt;b&gt;objConvertPostcode&lt;/b&gt;&amp;nbsp;is just something we made up ourselves. The &quot;&lt;b&gt;obj&lt;/b&gt;&quot; prefix means Object, and this is for our benefit, to remind us that the type of data inside it holds an Object, rather than a plain old Integer or String.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;After you type the word &quot;As&quot;, then hit your spacebar, you&#39;ll see s popup box appear. If you type the letters &quot;conv&quot;, you&#39;ll see the list automatically move down. The Class your created should be on that list, as in the next image:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The name of our Class is on the list&quot; height=&quot;207&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddModuleObject.gif&quot; width=&quot;170&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can double click the name of your Class to add it to your code.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But what you&#39;re doing in this step is setting up a pointer to your Class. You&#39;re telling VB where the Class can be found, and then storing this inside of the variable called&lt;b&gt;objConvertPostcode&lt;/b&gt;. If VB doesn&#39;t know where your Class is then it can&#39;t create an Object from it.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next line of code is the one that creates a new object from your Class:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;objConvertPostcode = New ConvertPostcode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You type the Name of your variable first, then an equals sign. To the right of the equals sign comes the word &quot;New&quot;. This is what tells VB to create a New Object. And the class its creating the New Object from is the one called ConvertPostcode.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You can actually type all of that on the same line:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;Dim objConvertPostcode As ConvertPostcode = New ConvertPostcode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This does two jobs: sets a pointer to where the Class is, and creates a new Object from the Class.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But there&#39;s reasons why you don&#39;t want to do it this way. One is that Objects take up space in memory. And you only really need to create them when they are needed. For example, what if the textbox was blank? You&#39;d want to check for this and invite the user to try again. If you&#39;ve written everything on one line, then you&#39;ve already created the Object before the Textbox has been checked. Instead, you could do something like this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;&lt;b&gt;If TextBox1.Text = &quot;&quot; Then&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;b&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;MsgBox &quot;Please try again&quot;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;Exit Sub&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;Else&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent3&quot; style=&quot;margin-left: 5em;&quot;&gt;objConvertPostcode = New ConvertPostcode&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt; &lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: black; font-weight: normal;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;End If&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Here&#39;s, the textbox is being checked first. If the user has left it blank then we bail out. If not, THEN we create an Object from our Class.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The next line in our code was this:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;NewCode = objConvertPostcode.DoConvert(TextBox1.Text)&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;First, we type the name of the variable we want to store the result of our Method into. In our case, the one called NewCode. After the equals sign, we type the name of our Object variable:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;objConvertPostcode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As soon as you type a full stop after your Object variable, you should see a popup box with the name of your new method on the list:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;Our Method is on the list!&quot; height=&quot;127&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddModuleMethod2.gif&quot; width=&quot;428&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The image above shows you that the name of our Method &quot;Do Convert&quot; has been recognised by VB. (You can tell it&#39;s a Method because of the purple block next to it.) But notice the tool tip - it&#39;s the first line from our Function!&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In between the round brackets, VB is telling us what type of data needs to be passed over to the Method - a String of text. The second &quot;As String&quot; tells you that the Method returns a value that needs to be stored somewhere.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So if you&#39;ve set up a Method that returns a value (a Function) then you need to store it in a variable.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;To get at the Method inside of your class, first type the name of your Object variable. The type a full stop. Look for the name of your Method in the pop up list that appears.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The final line of the code just assigns the value returned from the Method back to the textbox:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;b&gt;TextBox1.Text = NewCode&lt;/b&gt;&lt;/span&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Run your code and test it out. Click your Button and you should see the postcode change from &quot;ts1 4jh&quot; to &quot;TS1 4JH&quot;.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/7238308725542793220/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-create-methods-in-your-classes.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7238308725542793220'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/7238308725542793220'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/how-to-create-methods-in-your-classes.html' title='How to Create Methods in your Classes'/><author><name>Unknown</name><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-2315630515588192403.post-4999233356862909907</id><published>2010-08-26T13:49:00.000-07:00</published><updated>2011-04-10T04:37:00.745-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Create your  Classes"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>Create your own Classes in VB .NET</title><content type='html'>&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The big benefit of an Object Oriented Programming language is that you can create your own Objects. (It&#39;s an Object when you&#39;re using the code, remember, and a Class when you&#39;re not.)&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;We&#39;ll see how to do that now, as we create a very simple Class, and then turn that into an Object.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Class we&#39;ll create is a very simple one, and is intended to show you the basic technique of setting up a Class, then creating an object from it. The Class we&#39;ll create will convert the letters in a postcode to uppercase. We&#39;ll get the postcode from a textbox on a form. Off we go then.&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Start a new VB .NET project&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add a Textbox to your form, and leave it on the default&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;, Textbox1&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the&amp;nbsp;&lt;b&gt;Text&lt;/b&gt;&amp;nbsp;Property to&amp;nbsp;&lt;b&gt;ts1 4jh&amp;nbsp;&lt;/b&gt;(make sure the letters are lowercase and not upper, because our object will convert it.)&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Add a&amp;nbsp;&lt;b&gt;Button&lt;/b&gt;&amp;nbsp;to your form&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Once you have a new form with a Textbox and a Button on it, you need to add a Class. This is quite easy. It&#39;s just like&amp;nbsp;adding a Module. In fact, they look exactly the same!&lt;/div&gt;&lt;/div&gt;&lt;ul style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So from the VB menu bar, click on&amp;nbsp;&lt;b&gt;Project&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;From the drop down menu, click&amp;nbsp;&lt;b&gt;Add Class&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;&lt;br /&gt;
&lt;div class=&quot;leftMargin&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;You&#39;ll get this dialogue box popping up:&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div class=&quot;leftMargin&quot; style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Add New Item dialogue box&quot; height=&quot;418&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddClass.gif&quot; width=&quot;445&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The Class Template on the right will already be selected. The thing you need to change is the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;at the bottom. The default Name is Class1.vb. This is not terribly descriptive, and you&#39;ll have great problems working out what this class does, a few months down the line.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Change the&amp;nbsp;&lt;b&gt;Name&lt;/b&gt;&amp;nbsp;from Class1.vb to&amp;nbsp;&lt;b&gt;ConvertPostcode.vb&lt;/b&gt;. Then click the&amp;nbsp;&lt;b&gt;Open&lt;/b&gt;button.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When the code window for the class opens up, it will look like this:&lt;/div&gt;&lt;div style=&quot;text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;img alt=&quot;The Class code window&quot; border=&quot;1&quot; height=&quot;77&quot; src=&quot;http://www.homeandlearn.co.uk/net/images/AddClassCode.gif&quot; width=&quot;239&quot; /&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As you can see, there&#39;s not a great deal to look at! All we have is the&amp;nbsp;&lt;span style=&quot;color: blue;&quot;&gt;Public Class … End Class&lt;/span&gt;&amp;nbsp;code stub. The name of our Class is also there. But the code is in a separate window, and has a tab all to itself. It&#39;s this tab full of code that you reuse and turn into an object.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;text-align: left;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;What we have to do now is add the code that does the work - converts our postcode. But we can&#39;t just write this:&lt;/div&gt;&lt;/div&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;span class=&quot;Apple-style-span&quot; style=&quot;color: red;&quot;&gt;Dim ConvertPostcode As String&lt;/span&gt;&lt;/div&gt;&lt;span style=&quot;color: red;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;ConvertPostcode = StrConv(TextBox1.Text, VbStrConv.UpperCase)&lt;/div&gt;&lt;span class=&quot;TextIndent2&quot; style=&quot;margin-left: 2em;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;TextBox1.Text = ConvertPostcode&lt;/div&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;That would be all right for the button on our Form. But it&#39;s not all right for our Class. When you&#39;re designing a Class, your code has to go inside of things like Functions and Subs. You&#39;ll also see how to create your own properties for your objects.&lt;/div&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you set up a Function or Sub, you&#39;re actually creating Methods for your objects (A Method is code that actually does something, that performs an action&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/4999233356862909907/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/create-your-own-classes-in-vb-net.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4999233356862909907'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/4999233356862909907'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/create-your-own-classes-in-vb-net.html' title='Create your own Classes in VB .NET'/><author><name>Unknown</name><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-2315630515588192403.post-9109629535496083419</id><published>2010-08-26T13:48:00.000-07:00</published><updated>2011-04-10T04:37:00.750-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Classes and Objects"/><category scheme="http://www.blogger.com/atom/ns#" term="VB.NET"/><title type='text'>An Introduction to Classes and Objects</title><content type='html'>&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;VB.NET is an Object Oriented programming language. The Objects referred to are created from something called a Class. You&#39;ve already used Classes throughout this course. But we&#39;ll now have a closer look at them.&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt; Object Oriented programming&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The modern trend in programming languages is for code to be separated into chunks. When it&#39;s being used, each chunk of code (a chunk of code that opens text files, for example) is known as an Object. The code for the Object can then be reused whenever it is needed. Languages like C++ and Java are Object Oriented languages. Until Microsoft came out with VB.NET, the Visual Basic programming language was not OOP (object oriented programming). This time it is.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;Object Oriented programming has a steeper learning curve, and things like Encapsulation, Inheritance and Polymorphism have to be digested. We&#39;re not going quite that far in this beginner&#39;s course. But you should have a good, basic understanding of just what Object are by the end of this section, and how to create your own Objects.&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Classes&amp;nbsp;and Objects&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In VB.NET, a class is that chunk of code mentioned earlier. You&#39;ve been using Classes all the time during this course. The Form you&#39;ve started out with is a Class. If you look right at the top of the code window for a Form, you&#39;ll see:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Public Class&lt;/span&gt;&amp;nbsp;Form1&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The word &quot;Public&quot; means that other code can see it. Form1 is the name of the Class&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;If you look at the bottom of the coding window, you&#39;ll see End Class, signifying the end of the code for the Class.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you place a Button or a textbox on the Form, you&#39;re really adding it to the Form Class.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;When you start the Form, VB does something called instantiation. This basically means that your Form is being turned into an Object, and all the things needed for the creation of the Form are being set up for you (Your controls are being added, variables are being set up an initialised, etc).&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;And that&#39;s the basic difference between a Class and an Object:&amp;nbsp;&lt;b&gt;A Class is the code itself; the code becomes an Object when you start using it.&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;The NET&amp;nbsp;Framework&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The NET Framework is something that Microsoft have invested a lot of time, effort and money into creating. It&#39;s big. Very big. The way that programming will be done on a Microsoft machine from now on is with NET. And not just on a Microsoft machine. There&#39;s something called ADO.NET which is used for creating web site, and for manipulating databases. You can create applications for mobile phones and PDA&#39;s with NET. There is even a project in the making that will allow you to write a programme on a Windows machine that will then work on a computer NOT running Windows. All this is made possible with the NET Framework. But what is it?&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The NET Framework is a whole lot of Classes (called Namespaces) and the technology to get those Classes to work. The main component is called the Common Language Runtime. A Runtime is the thing that gets your code to actually run on a computer. Previously, these Runtime Languages were machine or programming language specific. The Runtime that gets a Java programme to work, for example, is different to the one that gets a C programme to work. With NET, more than 15 different programming languages can use the Common Language Runtime. One of these languages is, of course Visual Basic NET. Another is C# (pronounce C Sharp). They can all use the Common Language Runtime because of something called the Intermediate Language. (This is a sort of translator for the various languages, and is too advanced to go into for us.)&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;br /&gt;
&lt;/div&gt;&lt;/div&gt;&lt;h2 style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: justify;&quot;&gt;Namespaces&lt;/h2&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;A Namespace is a group of Classes which are grouped together. The System.IO Namespace you met earlier groups together Classes that you use to read and write to a file. System.Windows.Forms is another Namespace you&#39;ve met. In fact, you couldn&#39;t create your forms without this Namespace. But again, it is just a group of Classes huddling under the same umbrella.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;System itself is a Namespace. It&#39;s a top-level Namespace. Think of it as the leader of a hierarchy. IO and Windows would be part of this hierarchy, just underneath the leader. Each subsequent group of Classes is subordinate to the one the came before it. For example Forms is a group of Classes available to Windows, just as Windows is a group of Classes available to System. A single form is a Class available to Forms:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System.Windows.Forms.&lt;span style=&quot;color: blue;&quot;&gt;Form&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The dot notation is used to separate each group of Classes. A Button is also part of the Forms Class:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System.Windows.Forms.&lt;span style=&quot;color: blue;&quot;&gt;Button&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;As too is a Textbox:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System.Windows.Forms.&lt;span style=&quot;color: blue;&quot;&gt;TextBox&lt;/span&gt;&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The leader of the hierarchy is still System, though. Think of it as an army. You&#39;d have a Private who is subordinate to a Sergeant. The Sergeant would be subordinate to a Captain. And the Captain would be subordinate to a General. If the General wanted something done, he might ask the Captain to do it for him. The Captain would get the Sergeant to do it, and the Sergeant would then pick on a poor Private. So Button would be the Private, Forms would be the Sergeant, Windows would be the Captain, and System the General.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;In other words, there is a chain of command in NET programming. And if you don&#39;t follow the chain of command, you&#39;re in trouble!&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But you see this chain of command every time you type a full stop and a pop up box appears. When you&#39;re selecting an item from the list, you&#39;re selecting the next in the chain of command.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;This code at the top of the form window:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;&lt;span style=&quot;color: blue;&quot;&gt;Inherits&lt;/span&gt;&amp;nbsp;System.Windows.Forms.Form&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;means you don&#39;t have to keep typing the full chain of command every time you want to access a button on the form. This chain of command is inherited whenever you create a new VB.NET Form. There are plenty of times when a chain of command is not inherited though, and in that case you do have to type it all out. You did this when you referenced a StreamReader with:&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif; text-align: center;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;&lt;b&gt;System.&lt;span style=&quot;color: blue;&quot;&gt;IO&lt;/span&gt;.StreamReader&lt;/b&gt;&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;The IO Namespace is not inherited when you created a new Form, so you have to tell VB where it is in the hierarchy.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;But that&#39;s not quite the end of the story. The reason you using all of these long Namespaces is to get at a Property or Method - the chaps that do all the actual work! When you type&amp;nbsp;&lt;b&gt;Button1.Text = &quot;Click Me&quot;&lt;/b&gt;, Text is a Property of Button1. Button belongs to Form, which belongs to Forms, which belongs to Windows … etc.&lt;/div&gt;&lt;/div&gt;&lt;div style=&quot;font-family: Arial, Verdana, Geneva, Helvetica, sans-serif;&quot;&gt;&lt;div style=&quot;text-align: justify;&quot;&gt;So whenever you access a Property or Method of a control, just remember that rather long chain of command.&lt;/div&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://wlanguages14.blogspot.com/feeds/9109629535496083419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/introduction-to-classes-and-objects.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/9109629535496083419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2315630515588192403/posts/default/9109629535496083419'/><link rel='alternate' type='text/html' href='http://wlanguages14.blogspot.com/2010/08/introduction-to-classes-and-objects.html' title='An Introduction to Classes and Objects'/><author><name>Unknown</name><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>