473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

late binding problem with option strict

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 cast this
to?

Any suggestions appreciated.

Thanks,
Rich
Jan 28 '06 #1
3 1059
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.
Jan 28 '06 #2
"Rich" <Ri**@discussions.microsoft.com> schrieb
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?
Cast to the type of the object.
What do I need to
cast this to?


To type Itm:

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

Jan 28 '06 #3
"Rich" <Ri**@discussions.microsoft.com> schrieb:
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 'str1 = DirectCast(ht(0), Itm).mailSvr' instead. In .NET 2.0 you can
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/>

Jan 28 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: noone | last post by:
I like to write my code with optionstrict set to on, except for the late binding errors I get when there is a reason to change some value in a control on a postback, like: Label4.Text =...
1
by: Karl Lang | last post by:
Hi I've created a new configuration section in Web.Config to hold the connection string for my database. If I have Option Strict On I get a message "Option Strict On disallows late binding" when I...
11
by: Dieter Schwerdtfeger via DotNetMonster.com | last post by:
I have this function where i search through my database for items that were made on a specific date. The line "CType(dvClubs.Item(teller).Item(veld).ToShortDateString" gives me the error : option...
5
by: eBob.com | last post by:
In another thread VJ made me aware of Tag. Fantastic! I've been wanting this capability for a long time. But it seems that I cannot use it with Option Strict On. In an event handler I have ......
30
by: lgbjr | last post by:
hi All, I've decided to use Options Strict ON in one of my apps and now I'm trying to fix a late binding issue. I have 5 integer arrays: dim IA1(500), IA2(500), IA3(500), IA4(500), IA5(500) as...
17
by: David | last post by:
Hi all, I have the following problem: my program works fine, but when I add option strict at the top of the form, the following sub fails with an error that option strict does not allow late...
4
by: Heinz | last post by:
Hi all, I use VB.net 2003 and want to export data to Excel. Target PCs still have Office 2000 so I could not use Microsofts PIAs. Instead I use the included Excel 10 COM DLL from Microsoft....
6
by: Tim Roberts | last post by:
I've been doing COM a long time, but I've just come across a behavior with late binding that surprises me. VB and VBS are not my normal milieux, so I'm hoping someone can point me to a document...
4
by: Rippo | last post by:
Hi I have the following console application and am attempting to late bind a class with option strict on! However of course I cant and I get the following error "Option Strict On disallows late...
2
by: GS | last post by:
I have installed the ms PIA for ofc XP, and followed the article http://support.microsoft.com/kb/247412/ trying to paste into a worksheet However I got late binding not allowed errors .......
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.