|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
late binding problem with option strictoption ... option Strict On Public Structure Itm Dim mailSvr As String ... Public Sub New(ByVal a1 As String...) mailSvr = a1 End Sub End Structure Sub... ht = New Hashtable ht.Add("0", New Itm("thecorporatecounsel", ".net", "CC", "TCCNET_ID", "T")) ht.Add("0", New Itm("thecorporatecounsel", ".net", "CC", "TCCNET_ID", "T")) .... End Sub Sub ... str1 = ht(0).mailSvr <<<<----complains here now - say late binding not allowed .... End Sub What do I need to do to make it early binding? What do I need to cast this to? Any suggestions appreciated. Thanks, Rich The index 0 is actually a string "0". Still complains though with option
Strict on Sub ... str1 = ht("0").mailSvr <<<<----complains here now - say late binding not allowed .... End Sub I tried CType(ht("0").MailSvr, String) ---- still complains wait !!!! I just tried this and it stopped complaining !!! str1 = CType(ht("0"), Itm).mailSvr Nevermind. He's happy again.
Show quote
Hide quote
"Rich" <R***@discussions.microsoft.com> schrieb Cast to the type of the object.> This code worked before I added option strict. But I should do it > correctly. > > option ... > option Strict On > > Public Structure Itm > Dim mailSvr As String > ... > Public Sub New(ByVal a1 As String...) > mailSvr = a1 > End Sub > End Structure > > Sub... > ht = New Hashtable > ht.Add("0", New Itm("thecorporatecounsel", ".net", "CC", > "TCCNET_ID", "T")) ht.Add("0", New Itm("thecorporatecounsel", > ".net", "CC", "TCCNET_ID", "T")) ... > End Sub > > Sub ... > str1 = ht(0).mailSvr <<<<----complains here now - say late binding > not allowed > ... > End Sub > > What do I need to do to make it early binding? > What do I need to To type Itm:> cast this to? str1 = directcast(ht(0), Itm).mailSvr If you will access the hashtable in more situations, you should consider writing your own collection having a typed Item property. Armin
Show quote
Hide quote
"Rich" <R***@discussions.microsoft.com> schrieb: Use 'str1 = DirectCast(ht(0), Itm).mailSvr' instead. In .NET 2.0 you can > This code worked before I added option strict. But I should do it > correctly. > [...] > Public Structure Itm > Dim mailSvr As String > ... > Public Sub New(ByVal a1 As String...) > mailSvr = a1 > End Sub > End Structure > > Sub... > ht = New Hashtable > ht.Add("0", New Itm("thecorporatecounsel", ".net", "CC", "TCCNET_ID", > "T")) > ht.Add("0", New Itm("thecorporatecounsel", ".net", "CC", "TCCNET_ID", > "T")) > ... > End Sub > > Sub ... > str1 = ht(0).mailSvr <<<<----complains here now - say late binding not use one of the generic dictionary classes which can be parameterized with the item type instead of 'Hashtable'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/>
Whats's the problem using a enum like this?
Is It Possible to Retrieve a List of Declared Variables? Converted a solution to VS2005 and it is complaining: Variable 'PF2' is used before it has been assi setting datagrid column widths in code? Detect Concurrent Running Instances Inheritance and function issue FileDownload with WebBrowser Control - disable the Save? How do I maintain paragraph numbers into a new word document Run from Server or Workstation |
|||||||||||||||||||||||