473,543 Members | 3,906 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tag and Late Binding

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

Private Sub chkbxSelI_Click (ByVal sender As Object, ByVal e As
System.EventArg s)

MsgBox("bingo for number " & sender.Tag.ToSt ring)
End Sub

.... but with Option Strict On I get a complaint about "sender.Tag ".

I looked up a brief article about Late Binding and I get the
impression that this is just the way it is. If you use Late Binding
you cannot use Option Strict On.

But I don't understand exactly what Late Binding it is complaining
about. I would guess that the compiler is concerned that he can't be
sure that sender.Tag is an Integer. But when I cast sender.Tag to an
Integer I still get a Late Binding error on sender.Tag.

I hate to give up Option Strict On, so I thought I'd ask here if there
is some way to use Option Strict On and still use Late Binding. Maybe
casting was the right idea but I did it wrong? Or maybe there is some
other way to pass info to my event handler which does not involve Tag.
Although I really like the idea of Tag. I think that I am using it
exactly the way it is intended to be used.

Thanks, Bob

Nov 21 '05 #1
5 2033
Don't think so:

"In addition to the conditions described above, Option Strict generates an
error for:
* Any undeclared variable since it is implied that Option Strict also means
Option Explicit.
* Late-binding."

- Microsoft.


"eBob.com" <eB******@total lyfakeisp.com> schreef in bericht
news:do******** *************** *********@4ax.c om...
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 ...

Private Sub chkbxSelI_Click (ByVal sender As Object, ByVal e As
System.EventArg s)

MsgBox("bingo for number " & sender.Tag.ToSt ring)
End Sub

... but with Option Strict On I get a complaint about "sender.Tag ".

I looked up a brief article about Late Binding and I get the
impression that this is just the way it is. If you use Late Binding
you cannot use Option Strict On.

But I don't understand exactly what Late Binding it is complaining
about. I would guess that the compiler is concerned that he can't be
sure that sender.Tag is an Integer. But when I cast sender.Tag to an
Integer I still get a Late Binding error on sender.Tag.

I hate to give up Option Strict On, so I thought I'd ask here if there
is some way to use Option Strict On and still use Late Binding. Maybe
casting was the right idea but I did it wrong? Or maybe there is some
other way to pass info to my event handler which does not involve Tag.
Although I really like the idea of Tag. I think that I am using it
exactly the way it is intended to be used.

Thanks, Bob

Nov 21 '05 #2
Bob,

This is easy, you have to use Convert or Cast commands. (Convert converts,
Cast uses as).
Private Sub chkbxSelI_Click (ByVal sender As Object, ByVal e As
System.EventArg s)

MsgBox("bingo for number " & sender.Tag.ToSt ring)
End Sub

The sender is I assume a CheckBox object. Than you have to say
DirectCast(send er, CheckBox).Tag.T oString
"Use sender as a CheckBox because it is that (or derived from)".

That is all, one time you know this all problems about early binding are
gone.

When it is a value by instance a string from which you want to use the
contents as an integer, than you can say.
CInt("1234")
or in the long way
CType("1234",In teger)
' what is the same

Here DirectCast fails because "1234" is not an integer (or derives from
that).

In other words, you can use everywhere CType (ore the shortcuts) where you
can use DirectCast however not in the opposite way. Using (DirectCast) is of
course less expensive than converting.

ToString() is standard a converting command CType(x,String) , However that is
often overridden in different methods

I hope this helps?

Cor
Nov 21 '05 #3
> ToString() is standard a converting command CType(x,String) , However that
is often overridden in different methods

ToString() is standard a converting command CType(x,String) , However that
is often overridden in different classes

Nov 21 '05 #4
"eBob.com" <eB******@total lyfakeisp.com> schrieb:
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 ...

Private Sub chkbxSelI_Click (ByVal sender As Object, ByVal e As
System.EventArg s)

MsgBox("bingo for number " & sender.Tag.ToSt ring)
End Sub

... but with Option Strict On I get a complaint about "sender.Tag ".

I looked up a brief article about Late Binding and I get the
impression that this is just the way it is. If you use Late Binding
you cannot use Option Strict On.

But I don't understand exactly what Late Binding it is complaining
about. I would guess that the compiler is concerned that he can't be
sure that sender.Tag is an Integer.


No! 'sender' is of type 'Object', and 'Object' doesn't have a 'Tag'
property. You can solve the problem by casting 'sender' to 'Control', which
provides the 'Tag' property and is the superclass of all controls:

\\\
Dim SourceControl As Control = DirectCast(send er, Control)
MsgBox("Bingo for number " & CStr(SourceCont rol.Tag)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 21 '05 #5
On Thu, 17 Mar 2005 23:06:39 -0500, eBob.com
<eB******@total lyfakeisp.com> wrote:
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 ...

Private Sub chkbxSelI_Click (ByVal sender As Object, ByVal e As
System.EventAr gs)

MsgBox("bingo for number " & sender.Tag.ToSt ring)
End Sub

... but with Option Strict On I get a complaint about "sender.Tag ".

I looked up a brief article about Late Binding and I get the
impression that this is just the way it is. If you use Late Binding
you cannot use Option Strict On.

But I don't understand exactly what Late Binding it is complaining
about. I would guess that the compiler is concerned that he can't be
sure that sender.Tag is an Integer. But when I cast sender.Tag to an
Integer I still get a Late Binding error on sender.Tag.

I hate to give up Option Strict On, so I thought I'd ask here if there
is some way to use Option Strict On and still use Late Binding. Maybe
casting was the right idea but I did it wrong? Or maybe there is some
other way to pass info to my event handler which does not involve Tag.
Although I really like the idea of Tag. I think that I am using it
exactly the way it is intended to be used.

Thanks, Bob


Nov 21 '05 #6

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

Similar topics

21
3936
by: Mike MacSween | last post by:
Had some trouble with Word automation. Sorted it, in the process thought I would try late binding. Some people reccomend it. So this: ********************************************************* Public Sub MailMerge(strQuery As String, strTemplate As String) snip Dim doc As Word.Document Dim wrdApp As Word.Application snip Set wrdApp = New...
1
7918
by: JD Kronicz | last post by:
Hi .. I have an issue I have been beating my head against the wall on for some time. I am trying to use late binding for MS graph so that my end users don't have to worry about having the right version of the MS Graph type library. Up until now I have been walking them through the process of setting the references to include their version...
14
4285
by: Composer | last post by:
I've read many postings about the problem of Access.References.IsBroken and the consensus seems to be that late binding is the cure-all. I have a very complex Access application that needs hundreds of lines of code to format a Word document in a very specific way. Because my clients have various versions of Word, the problem of broken...
9
10396
by: Zlatko Matiæ | last post by:
I was reading about late binding, but I'm not completely sure what is to be done in order to adjust code to late binding... For example, I'm not sure if this is correct: early binding: Dim ws As DAO.Workspace Dim db As DAO.Database Dim qdf As DAO.QueryDef Dim rs As DAO.Recordset
30
2790
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 integer The integers in these arrays are actually pointers to different columns of data in a text file.
6
1884
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 that describes this. Here's the setup. We have a COM server, written in Python. For completeness, here is the script: ----- testserver.py...
2
8328
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 .... webOCWraooer,Copy // get the desired data into clapboard
3
16048
ADezii
by: ADezii | last post by:
The process of verifying that an Object exists and that a specified Property or Method is valid is called Binding. There are two times when this verification process can take place: during compile time (Early Binding) or run time (Late Binding). When you declare an Object Variable as a specific Data Type, you are using Early Binding so the...
14
2010
by: Siv | last post by:
hi, I am converting an application that writes to an Excel spreadsheet and the code trips the "option Strict" that I would like on because the parser says "option Strict On disallows late binding", I am struggling to understand why I am tripping this error. This is the code that causes the problems: XLApp.Goto("MonthTitleTL") ...
0
7402
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
7733
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
5883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5264
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1814
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.