473,394 Members | 1,759 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,394 software developers and data experts.

How to avoid Late Binding

In a nutshell, I need to get the name of the object that was just pressed
(in this case, the object will be a radioButton). I want to write one
handler for all four radio buttons and branch off depending on which one was
clicked..I can get it to work if I take off Option Strict and use late
Binding...but rather program an abacus than turn off Option Strict... here's
my code

Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged

Select Case sender.GetType.Name ' Returns RadioButton

'If I turn off option strict I can use sender.Name and it works but I know
I'm overlooking something trivial. So what I need is to know the name of
the control that was pressed. What am I overlooking?

Case "optFullTime"

MessageBox.Show(e.GetType.Name)

Case "optPartTime"

MessageBox.Show(e.GetType.Name)

Case "optContractor"

MessageBox.Show(e.GetType.Name)

Case "optTemporary"

MessageBox.Show(e.GetType.Name)

End Select
Jul 21 '05 #1
5 3733
William,
Use DirectCast to cast the sender object into a known type. You could use
either RadioButton or Control if you wanted just the name.

Something like:
Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged
Dim opt As Control = DirectCast(sender, Control)
Select Case opt.Name

or
Select Case DirectCast(sender, RadioButton).Name

I normally use the first as invariable I need mutliple accesses to the
sender.

Hope this helps
Jay

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl... In a nutshell, I need to get the name of the object that was just pressed
(in this case, the object will be a radioButton). I want to write one
handler for all four radio buttons and branch off depending on which one was clicked..I can get it to work if I take off Option Strict and use late
Binding...but rather program an abacus than turn off Option Strict... here's my code

Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged

Select Case sender.GetType.Name ' Returns RadioButton

'If I turn off option strict I can use sender.Name and it works but I know
I'm overlooking something trivial. So what I need is to know the name of
the control that was pressed. What am I overlooking?

Case "optFullTime"

MessageBox.Show(e.GetType.Name)

Case "optPartTime"

MessageBox.Show(e.GetType.Name)

Case "optContractor"

MessageBox.Show(e.GetType.Name)

Case "optTemporary"

MessageBox.Show(e.GetType.Name)

End Select

Jul 21 '05 #2
Worked like a Charm...Long Live Option Strict. Thanks again,

Bill
"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
In a nutshell, I need to get the name of the object that was just pressed
(in this case, the object will be a radioButton). I want to write one
handler for all four radio buttons and branch off depending on which one was clicked..I can get it to work if I take off Option Strict and use late
Binding...but rather program an abacus than turn off Option Strict... here's my code

Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged

Select Case sender.GetType.Name ' Returns RadioButton

'If I turn off option strict I can use sender.Name and it works but I know
I'm overlooking something trivial. So what I need is to know the name of
the control that was pressed. What am I overlooking?

Case "optFullTime"

MessageBox.Show(e.GetType.Name)

Case "optPartTime"

MessageBox.Show(e.GetType.Name)

Case "optContractor"

MessageBox.Show(e.GetType.Name)

Case "optTemporary"

MessageBox.Show(e.GetType.Name)

End Select

Jul 21 '05 #3
I have been using ctype(sender,controltype).property for example. Is
DirectCast better than Ctype. What is the difference.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
William,
Use DirectCast to cast the sender object into a known type. You could use
either RadioButton or Control if you wanted just the name.

Something like:
Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object,

ByVal
e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged


Dim opt As Control = DirectCast(sender, Control)
Select Case opt.Name

or
Select Case DirectCast(sender, RadioButton).Name

I normally use the first as invariable I need mutliple accesses to the
sender.

Hope this helps
Jay

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
In a nutshell, I need to get the name of the object that was just pressed (in this case, the object will be a radioButton). I want to write one
handler for all four radio buttons and branch off depending on which one

was
clicked..I can get it to work if I take off Option Strict and use late
Binding...but rather program an abacus than turn off Option Strict...

here's
my code

Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object,

ByVal
e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged

Select Case sender.GetType.Name ' Returns RadioButton

'If I turn off option strict I can use sender.Name and it works but I know I'm overlooking something trivial. So what I need is to know the name of the control that was pressed. What am I overlooking?

Case "optFullTime"

MessageBox.Show(e.GetType.Name)

Case "optPartTime"

MessageBox.Show(e.GetType.Name)

Case "optContractor"

MessageBox.Show(e.GetType.Name)

Case "optTemporary"

MessageBox.Show(e.GetType.Name)

End Select


Jul 21 '05 #4
vMike,
The way I view them is:

CType = Convert type
DirectCast = Cast type

Convert type will use conversion routines to physically change an object
from one type (String) into an object of a different type (Integer). If the
object is already that type a simple cast is done, however extra checks are
made to see if a conversion can occur (read as extra overhead).

Dim i As Integer
Dim s As String
i = CType(s, Integer)

Cast type allows an assignment of an object of a specific type to that
specific type, where the object is currently in a variable of a compatible
type, by compatible type I mean a base type. Or the specific type is an
Interface, and the object implements the interface. DirectCast is important
when using Option Strict On. You are using Option Strict On! Correct!

Dim o As Object = New Form1()
Dim frm As Form1
frm = DirectCast(o, Form1)
The following articles explains, among other things, conversions vs casting:
http://msdn.microsoft.com/library/de...tinternals.asp

Normally I use DirectCast, unless I have to use CType. I have to use CType
when DirectCast causes a compile error. Or I am actually doing a conversion.

Hope this helps
Jay
"vMike" <Mi************@nospam.gewarren.com.delete> wrote in message
news:bk**********@ngspool-d02.news.aol.com...
I have been using ctype(sender,controltype).property for example. Is
DirectCast better than Ctype. What is the difference.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
William,
Use DirectCast to cast the sender object into a known type. You could use
either RadioButton or Control if you wanted just the name.

Something like:
Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object,

ByVal
e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged


Dim opt As Control = DirectCast(sender, Control)
Select Case opt.Name

or
Select Case DirectCast(sender, RadioButton).Name

I normally use the first as invariable I need mutliple accesses to the
sender.

Hope this helps
Jay

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
In a nutshell, I need to get the name of the object that was just pressed (in this case, the object will be a radioButton). I want to write one
handler for all four radio buttons and branch off depending on which
one was
clicked..I can get it to work if I take off Option Strict and use late
Binding...but rather program an abacus than turn off Option Strict...

here's
my code

Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object,

ByVal
e As System.EventArgs) Handles optFullTime.CheckedChanged,
optContractor.CheckedChanged, optCurrent.CheckedChanged,
optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
optPartTime.CheckedChanged

Select Case sender.GetType.Name ' Returns RadioButton

'If I turn off option strict I can use sender.Name and it works but I

know I'm overlooking something trivial. So what I need is to know the name of the control that was pressed. What am I overlooking?

Case "optFullTime"

MessageBox.Show(e.GetType.Name)

Case "optPartTime"

MessageBox.Show(e.GetType.Name)

Case "optContractor"

MessageBox.Show(e.GetType.Name)

Case "optTemporary"

MessageBox.Show(e.GetType.Name)

End Select



Jul 21 '05 #5
Jay
Yes Option Strict is On for sure!! I think I will change my ctype's to
directcast's were possible. Looks like it will be a little less overhead.
Thanks for the information.
Mike

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:OB****************@TK2MSFTNGP11.phx.gbl...
vMike,
The way I view them is:

CType = Convert type
DirectCast = Cast type

Convert type will use conversion routines to physically change an object
from one type (String) into an object of a different type (Integer). If the object is already that type a simple cast is done, however extra checks are made to see if a conversion can occur (read as extra overhead).

Dim i As Integer
Dim s As String
i = CType(s, Integer)

Cast type allows an assignment of an object of a specific type to that
specific type, where the object is currently in a variable of a compatible
type, by compatible type I mean a base type. Or the specific type is an
Interface, and the object implements the interface. DirectCast is important when using Option Strict On. You are using Option Strict On! Correct!

Dim o As Object = New Form1()
Dim frm As Form1
frm = DirectCast(o, Form1)
The following articles explains, among other things, conversions vs casting: http://msdn.microsoft.com/library/de...tinternals.asp
Normally I use DirectCast, unless I have to use CType. I have to use CType
when DirectCast causes a compile error. Or I am actually doing a conversion.
Hope this helps
Jay
"vMike" <Mi************@nospam.gewarren.com.delete> wrote in message
news:bk**********@ngspool-d02.news.aol.com...
I have been using ctype(sender,controltype).property for example. Is
DirectCast better than Ctype. What is the difference.

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message
news:%2****************@TK2MSFTNGP09.phx.gbl...
William,
Use DirectCast to cast the sender object into a known type. You could use either RadioButton or Control if you wanted just the name.

Something like:
> Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal
> e As System.EventArgs) Handles optFullTime.CheckedChanged,
> optContractor.CheckedChanged, optCurrent.CheckedChanged,
> optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
> optPartTime.CheckedChanged

Dim opt As Control = DirectCast(sender, Control)
Select Case opt.Name

or
Select Case DirectCast(sender, RadioButton).Name

I normally use the first as invariable I need mutliple accesses to the
sender.

Hope this helps
Jay

"William Ryan" <do********@comcast.nospam.net> wrote in message
news:ut**************@TK2MSFTNGP10.phx.gbl...
> In a nutshell, I need to get the name of the object that was just

pressed
> (in this case, the object will be a radioButton). I want to write one > handler for all four radio buttons and branch off depending on which one was
> clicked..I can get it to work if I take off Option Strict and use late > Binding...but rather program an abacus than turn off Option Strict... here's
> my code
>
> Private Sub optFullTime_CheckedChanged(ByVal sender As System.Object, ByVal
> e As System.EventArgs) Handles optFullTime.CheckedChanged,
> optContractor.CheckedChanged, optCurrent.CheckedChanged,
> optFormerEmployees.CheckedChanged, optTemporary.CheckedChanged,
> optPartTime.CheckedChanged
>
> Select Case sender.GetType.Name ' Returns RadioButton
>
> 'If I turn off option strict I can use sender.Name and it works but
I know
> I'm overlooking something trivial. So what I need is to know the
name of
> the control that was pressed. What am I overlooking?
>
> Case "optFullTime"
>
> MessageBox.Show(e.GetType.Name)
>
> Case "optPartTime"
>
> MessageBox.Show(e.GetType.Name)
>
> Case "optContractor"
>
> MessageBox.Show(e.GetType.Name)
>
> Case "optTemporary"
>
> MessageBox.Show(e.GetType.Name)
>
> End Select
>
>



Jul 21 '05 #6

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

Similar topics

21
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: *********************************************************...
1
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...
14
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...
9
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...
3
by: Thomas Müller-Lynch | last post by:
How can I avoid late binding with the directive strict = tru My ASP .net-file looks like this <%@DEBUG=true TRACE=true Strict=false EXPLICIT=true% .. dim footerValues as Arra footerValues =...
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 ......
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...
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 .......
3
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...
14
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...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.