Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old March 13th, 2006, 03:35 AM
Vincent
Guest
 
Posts: n/a
Default "Casting" an object in Microsoft Access

Regarding the dropdetect function, defined as follows:

Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer,
Shift As Integer, X As Single, Y As Single)

Is it possible to cast the Control parameter, DropCtrl, to a TextBox
object? The underlying control is in fact a textbox which I wish to
redraw given the X and Y parameters above. In Java, you could simply
declare a TextBox reference and assign it to the Control object as
follows:

Dim myTextBox as TextBox
myTextBox = (TextBox)DropCtrl

Is there any analogous code in VBA? Thanks.

-Vincent

  #2  
Old March 13th, 2006, 04:05 AM
Allen Browne
Guest
 
Posts: n/a
Default Re: "Casting" an object in Microsoft Access

Try:
Dim myTextBox as TextBox
Set myTextBox = DropCtl

Anything you can do with a TextBox object, you should also be able to do
directly with a Control object anyway, so I'm not sure why you would need to
do that.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Vincent" <animedreamer@verizon.net> wrote in message
news:1142220119.885543.148010@i39g2000cwa.googlegr oups.com...[color=blue]
> Regarding the dropdetect function, defined as follows:
>
> Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer,
> Shift As Integer, X As Single, Y As Single)
>
> Is it possible to cast the Control parameter, DropCtrl, to a TextBox
> object? The underlying control is in fact a textbox which I wish to
> redraw given the X and Y parameters above. In Java, you could simply
> declare a TextBox reference and assign it to the Control object as
> follows:
>
> Dim myTextBox as TextBox
> myTextBox = (TextBox)DropCtrl
>
> Is there any analogous code in VBA? Thanks.
>
> -Vincent[/color]


  #3  
Old March 13th, 2006, 04:05 AM
david epsom dot com dot au
Guest
 
Posts: n/a
Default Re: "Casting" an object in Microsoft Access

You can only do implicit casting by assigning
the object to a variable of different type

That is, you can do implicit casting without
a cast operator:

Dim myTextBox as Access.TextBox
set myTextBox = DropCtrl

or

Sub dropdetect(DropFrm As Form, _
DropCtrl As Access.Textbox, _
Button As Integer, _
Shift As Integer, _
X As Single, Y As Single)


(david)

"Vincent" <animedreamer@verizon.net> wrote in message
news:1142220119.885543.148010@i39g2000cwa.googlegr oups.com...[color=blue]
> Regarding the dropdetect function, defined as follows:
>
> Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer,
> Shift As Integer, X As Single, Y As Single)
>
> Is it possible to cast the Control parameter, DropCtrl, to a TextBox
> object? The underlying control is in fact a textbox which I wish to
> redraw given the X and Y parameters above. In Java, you could simply
> declare a TextBox reference and assign it to the Control object as
> follows:
>
> Dim myTextBox as TextBox
> myTextBox = (TextBox)DropCtrl
>
> Is there any analogous code in VBA? Thanks.
>
> -Vincent
>[/color]


  #4  
Old March 14th, 2006, 12:35 PM
Terry Kreft
Guest
 
Posts: n/a
Default Re: "Casting" an object in Microsoft Access

When casting you really should test that the interface is supported which
you do uing the TypeOf predicate you can then simply assign variable to
variable as follows:-

Dim myTextBox as TextBox

If TypeOf DropCtrl is textbox then
Set myTextBox = DropCtrl
' ...
Else
' Do something else because it's not a textbox
end if


--

Terry Kreft


"Vincent" <animedreamer@verizon.net> wrote in message
news:1142220119.885543.148010@i39g2000cwa.googlegr oups.com...[color=blue]
> Regarding the dropdetect function, defined as follows:
>
> Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer,
> Shift As Integer, X As Single, Y As Single)
>
> Is it possible to cast the Control parameter, DropCtrl, to a TextBox
> object? The underlying control is in fact a textbox which I wish to
> redraw given the X and Y parameters above. In Java, you could simply
> declare a TextBox reference and assign it to the Control object as
> follows:
>
> Dim myTextBox as TextBox
> myTextBox = (TextBox)DropCtrl
>
> Is there any analogous code in VBA? Thanks.
>
> -Vincent
>[/color]


  #5  
Old March 14th, 2006, 12:35 PM
Terry Kreft
Guest
 
Posts: n/a
Default Re: "Casting" an object in Microsoft Access

Very early binding which gives a performance increase (I know, I know it
won't even be noticeable but I had to give the _correct_ answer first)

Probably more important to some is that casting to the correct interface
then gives you the correct information in the context sensitive drop-downs
in the editor.


--

Terry Kreft


"Allen Browne" <AllenBrowne@SeeSig.Invalid> wrote in message
news:4414ed0c$0$23304$5a62ac22@per-qv1-newsreader-01.iinet.net.au...[color=blue]
> Try:
> Dim myTextBox as TextBox
> Set myTextBox = DropCtl
>
> Anything you can do with a TextBox object, you should also be able to do
> directly with a Control object anyway, so I'm not sure why you would need[/color]
to[color=blue]
> do that.
>
> --
> Allen Browne - Microsoft MVP. Perth, Western Australia.
> Tips for Access users - http://allenbrowne.com/tips.html
> Reply to group, rather than allenbrowne at mvps dot org.
>
> "Vincent" <animedreamer@verizon.net> wrote in message
> news:1142220119.885543.148010@i39g2000cwa.googlegr oups.com...[color=green]
> > Regarding the dropdetect function, defined as follows:
> >
> > Sub dropdetect(DropFrm As Form, DropCtrl As Control, Button As Integer,
> > Shift As Integer, X As Single, Y As Single)
> >
> > Is it possible to cast the Control parameter, DropCtrl, to a TextBox
> > object? The underlying control is in fact a textbox which I wish to
> > redraw given the X and Y parameters above. In Java, you could simply
> > declare a TextBox reference and assign it to the Control object as
> > follows:
> >
> > Dim myTextBox as TextBox
> > myTextBox = (TextBox)DropCtrl
> >
> > Is there any analogous code in VBA? Thanks.
> >
> > -Vincent[/color]
>
>[/color]


 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles