473,783 Members | 2,475 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_Che ckedChanged(ByV al sender As System.Object, ByVal
e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged

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 "optFullTim e"

MessageBox.Show (e.GetType.Name )

Case "optPartTim e"

MessageBox.Show (e.GetType.Name )

Case "optContrac tor"

MessageBox.Show (e.GetType.Name )

Case "optTempora ry"

MessageBox.Show (e.GetType.Name )

End Select
Jul 21 '05 #1
5 3755
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_Che ckedChanged(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged
Dim opt As Control = DirectCast(send er, Control)
Select Case opt.Name

or
Select Case DirectCast(send er, RadioButton).Na me

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

Hope this helps
Jay

"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ut******** ******@TK2MSFTN GP10.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_Che ckedChanged(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged

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 "optFullTim e"

MessageBox.Show (e.GetType.Name )

Case "optPartTim e"

MessageBox.Show (e.GetType.Name )

Case "optContrac tor"

MessageBox.Show (e.GetType.Name )

Case "optTempora ry"

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********@com cast.nospam.net > wrote in message
news:ut******** ******@TK2MSFTN GP10.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_Che ckedChanged(ByV al sender As System.Object, ByVal e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged

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 "optFullTim e"

MessageBox.Show (e.GetType.Name )

Case "optPartTim e"

MessageBox.Show (e.GetType.Name )

Case "optContrac tor"

MessageBox.Show (e.GetType.Name )

Case "optTempora ry"

MessageBox.Show (e.GetType.Name )

End Select

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

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message
news:%2******** ********@TK2MSF TNGP09.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_Che ckedChanged(ByV al sender As System.Object,

ByVal
e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged


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

or
Select Case DirectCast(send er, RadioButton).Na me

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

Hope this helps
Jay

"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ut******** ******@TK2MSFTN GP10.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_Che ckedChanged(ByV al sender As System.Object,

ByVal
e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged

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 "optFullTim e"

MessageBox.Show (e.GetType.Name )

Case "optPartTim e"

MessageBox.Show (e.GetType.Name )

Case "optContrac tor"

MessageBox.Show (e.GetType.Name )

Case "optTempora ry"

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.gewarre n.com.delete> wrote in message
news:bk******** **@ngspool-d02.news.aol.co m...
I have been using ctype(sender,co ntroltype).prop erty for example. Is
DirectCast better than Ctype. What is the difference.

"Jay B. Harlow [MVP - Outlook]" <Ja********@ema il.msn.com> wrote in message news:%2******** ********@TK2MSF TNGP09.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_Che ckedChanged(ByV al sender As System.Object,

ByVal
e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged


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

or
Select Case DirectCast(send er, RadioButton).Na me

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

Hope this helps
Jay

"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ut******** ******@TK2MSFTN GP10.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_Che ckedChanged(ByV al sender As System.Object,

ByVal
e As System.EventArg s) Handles optFullTime.Che ckedChanged,
optContractor.C heckedChanged, optCurrent.Chec kedChanged,
optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
optPartTime.Che ckedChanged

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 "optFullTim e"

MessageBox.Show (e.GetType.Name )

Case "optPartTim e"

MessageBox.Show (e.GetType.Name )

Case "optContrac tor"

MessageBox.Show (e.GetType.Name )

Case "optTempora ry"

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********@ema il.msn.com> wrote in message
news:OB******** ********@TK2MSF TNGP11.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.gewarre n.com.delete> wrote in message
news:bk******** **@ngspool-d02.news.aol.co m...
I have been using ctype(sender,co ntroltype).prop erty for example. Is
DirectCast better than Ctype. What is the difference.

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

message
news:%2******** ********@TK2MSF TNGP09.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_Che ckedChanged(ByV al sender As System.Object, ByVal
> e As System.EventArg s) Handles optFullTime.Che ckedChanged,
> optContractor.C heckedChanged, optCurrent.Chec kedChanged,
> optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
> optPartTime.Che ckedChanged

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

or
Select Case DirectCast(send er, RadioButton).Na me

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

Hope this helps
Jay

"William Ryan" <do********@com cast.nospam.net > wrote in message
news:ut******** ******@TK2MSFTN GP10.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_Che ckedChanged(ByV al sender As System.Object, ByVal
> e As System.EventArg s) Handles optFullTime.Che ckedChanged,
> optContractor.C heckedChanged, optCurrent.Chec kedChanged,
> optFormerEmploy ees.CheckedChan ged, optTemporary.Ch eckedChanged,
> optPartTime.Che ckedChanged
>
> 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 "optFullTim e"
>
> MessageBox.Show (e.GetType.Name )
>
> Case "optPartTim e"
>
> MessageBox.Show (e.GetType.Name )
>
> Case "optContrac tor"
>
> MessageBox.Show (e.GetType.Name )
>
> Case "optTempora ry"
>
> 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
3977
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 Word.Application
1
7939
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 of MS Graph library. My problem is that I can not seem to get the syntax correct .. or perhaps...
14
4312
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 references comes up. I wish Microsoft had implemented a reasonable solution, so that VBA could do...
9
10428
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
3
1439
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 = split("val1,val2,val3,val4,val5", "," .. dim strDept as String = footerValues(0
5
2054
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 ... Private Sub chkbxSelI_Click(ByVal sender As Object, ByVal e As System.EventArgs) MsgBox("bingo for number " & sender.Tag.ToString) End Sub
6
1894
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 ----- import pythoncom
2
8350
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
16072
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 verification can take place during compile time. When you declare a Variable of the generic Object Data...
14
2041
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") 'Goes to bookmark in sheet r = XLApp.ActiveCell.Row 'sets variable r equal
0
9643
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9480
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10315
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10083
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7494
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6737
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5379
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.