473,394 Members | 1,737 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.

"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

Mar 13 '06 #1
4 14473
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" <an**********@verizon.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

Mar 13 '06 #2
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" <an**********@verizon.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

Mar 13 '06 #3
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" <an**********@verizon.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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

Mar 14 '06 #4
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" <Al*********@SeeSig.Invalid> wrote in message
news:44***********************@per-qv1-newsreader-01.iinet.net.au...
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" <an**********@verizon.net> wrote in message
news:11**********************@i39g2000cwa.googlegr oups.com...
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


Mar 14 '06 #5

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

Similar topics

1
by: sang park | last post by:
Hi all - Just started learning Python this past week and had a question about using the lists in python with objects. (code attached below). basically, what i want to do is read an xml file,...
13
by: Jack MacRank | last post by:
Hello, I'm coding a webform application in C# (ASP.NET 1.1 SP1 with VS.NET 2003 Pro on WinXP SP2 using IIS 5.1). I created a seperate "data" class to house all the MySQL connection and sql...
7
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play...
13
by: dee | last post by:
Hi My code complies the following line: Session("passed") = 1 but puts wiggly error line under the second Session("passed") in the following expression: Session("passed") = Session("passed") +...
4
by: Mike Cooper | last post by:
There is something about inherited classes I evidently don't know... I wrote the following class: Class Class1 inherits System.Windows.Forms.DataGridTextBoxColumn End Class There is...
3
by: JimM | last post by:
I am trying to create a method in VS 2003 that validates an object argument is of the proper type and within a range of values. I am trying to use a Type to define the casting and object type for...
5
by: SunnyDrake | last post by:
HI! I wrting some program part of it is XML config parser which contains some commands(for flexibility of engenie). how do i more simple(if it possible not via System.Reflection or...
5
by: Ronald Raygun | last post by:
If I have the following class heirarchy: class A{ protected $m_type; function type(){return $this->m_type;} } class B extends A{} class C extends B{}
7
by: Robert | last post by:
Thanks George, I really am grateful for attempts to be helpful, but this really doesn't answer the question in my OP. What I am looking for is an explanation of WHY things are this way (I was...
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: 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
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,...
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.