Wrox Programmer Forums
|
BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5
This is the forum to discuss the Wrox book Beginning Visual Basic 2005 Databases by Thearon Willis; ISBN: 9780764588945
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 17th, 2006, 12:51 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 6 / Appendix B - Admin / WDABase Classes

I am reading through Chapter 6, and I am confused on page 111. I see how (in Admin.vb)

    Private Sub LoadProjects()
        'Declare variables
        Dim objListViewItem As ListViewItem

        'Inititalize a new instance of the data access base class
        Using objData As New WDABase

loads and begins creating the connection to the database. What is confusing me is how we are calling the "Public Sub New()" portion of WDABase.vb. It seems like I am used to defining a variable and then later calling that variable by assigning it as a "New" whatever type it is, then defining a value. Is there underlying code to that syntax that I don't see? Have we overwritten the default "New()" method(?) with "Public Sub New()" in Admin.vb? Have we merely defined the "New()" method(again, is that the right term?) for the WDABase class? Will we have to do that for every class we create? Does this:

        Using objData As New WDABase
or
        objData = New WDABase (does that assign the same properties
                               as the "Using" line above?)

automatically do this:

        objData.Connection = (Connection string defined in "Public Sub New()" in WDABase)

along with the other commands in "New()"?

Sorry that this was so verbose, but I just want to make sure I really get this stuff, not just that I can copy Thearon's code from his book. Not much use to me if that's all I get from reading this book.

By the way, again, this book is awesome!!!

 
Old May 17th, 2006, 05:06 PM
Authorized User
 
Join Date: Dec 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to luishrd
Default

I am also very green, but this is what understand so far from the book, maybe we can figure it out together...

- Remember that to use an object you first declare a variable and then initialize it using the 'New' keyword like this:
  Dim objMyObject As MyClass 'Declare the variable
  objMyObject = New MyClass 'Initialize it using the 'New' Keyword

  You could also do it all in one line like this:
  Dim objMyObject As New MyClass 'the same as the two lines above

- Every class has a constructor that is executed every time you initialize an object derived from the class.

   objMyObject = New MyClass 'here the code in the constructor runs.
   Dim objMyObject As New MyClass 'here too cause we are initializing at same time we declare.

- The constructor of the object is a 'Sub' procedure called 'New' that is defined on the class. eg.
Public Class MyClass
  Public Sub New()
    'code is here runs when the class is initialized into an object.
  End Sub
End Class

So for what I reckon, every time you instantiate an object the first thing it does is run whatever code is on the 'Sub New' on the parent class, wich is the class constructor.

I surely hope you got all that gibberish I just wrote LOL


__________________________
I'm just a noob
 
Old May 17th, 2006, 05:17 PM
Authorized User
 
Join Date: Dec 2003
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to luishrd
Default

Another thing:

The New Keyword is used with objects, not with variables.

Dim strSQL As String 'Here we declare the Variable
strSQL = "Value of the String" 'Here we initialize it to a value.

Dim objData as WDABase 'Here we declared the object variable
objData = New WDABase 'Here we initialized it to an instance of the class

just a note...


__________________________
I'm just a noob
 
Old May 20th, 2006, 05:54 AM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

I hope this clears this up but if not please post another question here. The Using...End Using statement is designed to call both the contructor and destructor for the object that it is using, in this case WDABase. The Using...End Using statement can only be used on objects that implement the IDisposable interface and have a New constructor.

Thearon





Similar Threads
Thread Thread Starter Forum Replies Last Post
Confused between Appendix B and Chapter 1 xzander BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 10 February 19th, 2008 07:26 PM
I can't login admin account all chapter ? pop99 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 June 4th, 2006 05:17 AM
Appendix B - WDABase class scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 2 May 20th, 2006 05:45 AM
Appendix chapter code jdz66 BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 13th, 2006 02:22 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.