Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB.NET 1.0 > BOOK: Beginning VB.NET Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning VB.NET Databases
This is the forum to discuss the Wrox book Beginning VB.NET Databases by Thearon Willis; ISBN: 9780764568008
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 9th, 2006, 02:32 AM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Guid Error in listview click event

Greetings:

I'm getting an error message about an improper format for a GUID in the following sub. It is located in the Admin form; I've worked my way halfway through Chapter 12, Selecting Data. The error is a System.FormatException, "Guid should contain 32 digits with 4 dashes".


Private Sub lvwRoles_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwRoles.Click
        'initialize a new instance of the business logic component
        objRoles = New WroxBusinessLogic.WBLRoles(strCompany, strApplication)

        Try
            'get the specific role selected in lv control
            objDataSet = objRoles.GetRole(New Guid(lvwRoles.SelectedItems.Item(0).Tag.ToString)) 'error occurs

The error occurs on the first step of the debugger after it arrives at this line. The functionally similar sub:

Private Sub lvwUsers_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvwUsers.Click
        objUsers = New WroxBusinessLogic.WBLUsers(strCompany, strApplication)

        Try
            'get the specific user selected in the lv control
            objDataSet = objUsers.GetUser(New Guid(lvwUsers.SelectedItems.Item(0).Tag.ToString))

works just fine. The debugger steps through all called procedures in the business logic, data access, and base components. In the problem sub above, apparently none of those procedures are even called, as the debugger goes straight to the Catch line from objDataSet. I've looked for typos in the constructor for WBLRoles, but haven't found anything. Any other suggestions?

Thanks!

Reply With Quote
  #2 (permalink)  
Old February 13th, 2006, 12:41 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

The Tag property contains the GUID? Did you try to check the value and see if that really is the case, and it isn't looking at something else?

Brian
Reply With Quote
  #3 (permalink)  
Old February 13th, 2006, 09:24 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Brian
Yes, the tag references the guid RoleID, similar to the other listview click events. The code is straight out of the book. My real question at this point is what the debugger is telling me by just bouncing off that line, and going straight to the Catch block. When I take a working listview click event, and then screw up the code on purpose, the debugger works it way through all the referenced procedures until it hits the error, and then passes the error message back to the calling procedure. What does it mean when the debugger goes straight to the Catch block? The obvious answer is that the error is in that line, but that line of code is identical to the code in the download, its functionally similar to the other listview click events, and there are no syntax errors in it. So, what is the debugger telling me?

Reply With Quote
  #4 (permalink)  
Old February 14th, 2006, 12:53 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

The debugger isn't trying to tell you anything per se. The catch line handles errors; that's its functionality. The lines grouped in the try section; one of them have an error which the catch handles and does something appropriately. Is that what you mean?

Brian
Reply With Quote
  #5 (permalink)  
Old February 14th, 2006, 08:15 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Try setting a breakpoint on this line of code:

objDataSet = objRoles.GetRole(New Guid(lvwRoles.SelectedItems.Item(0).Tag.ToString))

When you encounter the breakpoint, query the value for lvwRoles.SelectedItems.Item(0).Tag.ToString in the Command window to see what it contains.

Thearon
Reply With Quote
  #6 (permalink)  
Old February 14th, 2006, 10:53 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Thearon, that gives me something I can work with. The command line query shows that this expression works out to the role name, e.g. "manager", in the problematic sub. In a functional listview click event, this expression returns a guid. That gives me a clear idea how to fix this.

But I'm still curious...why doesn't the debugger step through all the called procedures until it gets to the error? This jumping straight to the Catch block doesn't give much to work with.
Thanks again

Reply With Quote
  #7 (permalink)  
Old February 14th, 2006, 10:59 PM
Thearon's Avatar
Wrox Author
 
Join Date: Dec 2003
Location: Fuquay Varina, NC, USA.
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Is the objRoles instantiated? Try commenting out the Try...Catch block and let Visual Studio catch and display the error to see what it reports?

Thearon
Reply With Quote
  #8 (permalink)  
Old February 15th, 2006, 09:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

That is the nature of catch though; an error will keep trying to propogate up the call stack until it is caught; only when it is not caught, does the error show directly in the Visual Studio designer. You have to remove the try catch block (or comment out) as mentioned above.

If you look at the call stack, it does show the lines executed in the order they fire, and you can trace it back some that way.

Brian
Reply With Quote
  #9 (permalink)  
Old February 15th, 2006, 07:27 PM
Registered User
 
Join Date: Nov 2005
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thankyou, I will look at those things to help me understand the debugger. Using the command line to evaluate the problem line of code pointed to a logic error in the LoadRoles function, where I'd typed in "RoleName" instead of "RoleID" in an AddParameter line. I learn a lot more debugging my mistakes than I do from typing them in in the first place. Thanks for your help.

Reply With Quote
  #10 (permalink)  
Old February 16th, 2006, 01:57 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Sure, the Immediate Window does help in identifying these things also. it is another useful tool, as well as the autos window which shows the immediate variables in scope.

Brian
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Display ListView click value Intel.Leiria Access VBA 0 September 27th, 2005 03:09 PM
Remove entries from listview on click neo_jakey Pro VB 6 3 December 23rd, 2004 04:44 PM
Remove entries from listview on click neo_jakey Beginning VB 6 2 September 28th, 2004 09:50 AM
Remove entries from listview and database on click neo_jakey Pro VB Databases 1 September 20th, 2004 12:21 PM
Remove entries from listview and database on click neo_jakey VB Databases Basics 2 September 20th, 2004 10:37 AM



All times are GMT -4. The time now is 02:48 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.