O'Reilly Forums: Vb Samples For Download - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Vb Samples For Download

#1 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 334
  • Joined: 17-September 08

Posted 05 June 2011 - 09:04 AM

There has been very little demand for VB samples, but one unhappy VB developer is enough to justify doing it - it was just a matter of creating the time. I've converted a chunk of the samples that are now available from the download page at learnentityframework.com/downloads.
0

#2 User is offline   kstevens715 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 10-August 11

Posted 10 August 2011 - 12:14 PM

Julie,

I develop in Visual Basic and I'm pretty use to seeing code samples in C# so I don't typically have problems understanding them. However, there is one code snippet in chapter 26th of the 2nd edition that I cannot for the life of me figure out. It's the GetStoredList method on page 765. I can't figure how how to cast a list as a List(Of T). No matter what I try the VB compiler doesn't like it. I'd love to see chapter 26 in VB.
0

#3 User is offline   Bill9717 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 27-December 12

Posted 04 February 2013 - 06:53 AM

Hi -- Like kstevens715 I also prefer VB.NET and can get by with C# but the issue in Chapter 26 that kstevens715 mentions has also tripped me up. Any idea on how to solve it? FYI, the code I'm using is here:

Private Function GetStoredList(Of T As Class)() As List(Of T)
         Dim typeName As String = GetType(T).Name
         Dim _list As List(Of T) = Nothing

         Select Case typeName
             Case "Activity" : _list = TryCast(_activities, List(Of Activity))
             Case "Destination" : _list = TryCast(_destinations, List(Of Destination))
             Case "Lodging" : _list = TryCast(_lodgings, List(Of Lodging))
             Case Else
                 Throw New NotSupportedException("You cannot make an UntrackedList from this type.")
         End Select

         Return _list
End Function


And the compiler errors are as follows:

  • Value of type 'System.Collections.Generic.List(Of BAGA.Activity)' cannot be converted to 'System.Collections.Generic.List(Of T)'.
  • Value of type 'System.Collections.Generic.List(Of BAGA.Destination)' cannot be converted to 'System.Collections.Generic.List(Of T)'.
  • Value of type 'System.Collections.Generic.List(Of BAGA.Lodging)' cannot be converted to 'System.Collections.Generic.List(Of T)'.


Help is greatly appreciated! :)
0

#4 User is offline   JulieLerman 

  • Advanced Member
  • PipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 334
  • Joined: 17-September 08

Posted 06 February 2013 - 08:11 AM

Bill,
I just spent some time converting and then fixing up the VB soluiton until it finally worked. The method you pointed out (well both GetSortedList and SetSortedList) were the biggest problem. The converter couldn't figure it out nor could I. But someone actually asked about converting this same code from my book on Stackoverflow and someone else provided the solution! There was one other tough spot which was the expression passed in to the SortedList method. I finally figured out to change "object" to string and it worked!
I ran through the app, retrieving, editing and inserting records so I think it's really all working now.

Oh, I just added the solution to the downloads page on the website: http://learnentityfr.../downloads/#2ed

Thanks for the inspiration. Sorry for the trouble. I get about one "help with the VB' a year.

Julie
0

#5 User is offline   Bill9717 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 27-December 12

Posted 06 February 2013 - 08:49 AM

Thanks, Julie! Never would have thought of the CObj() solution.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users