 |
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 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
|
|
|
|

February 9th, 2006, 02:32 AM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!
|
|

February 13th, 2006, 12:41 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 13th, 2006, 09:24 PM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

February 14th, 2006, 12:53 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 14th, 2006, 08:15 PM
|
 |
Wrox Author
|
|
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
|
|
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
|
|

February 14th, 2006, 10:53 PM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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
|
|

February 14th, 2006, 10:59 PM
|
 |
Wrox Author
|
|
Join Date: Dec 2003
Posts: 396
Thanks: 0
Thanked 8 Times in 8 Posts
|
|
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
|
|

February 15th, 2006, 09:39 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

February 15th, 2006, 07:27 PM
|
|
Registered User
|
|
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

February 16th, 2006, 01:57 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|
 |