?
Solved

Faster Control Type Checking in "View" Menu's Code

Posted on 2004-04-27
5
Medium Priority
?
251 Views
Last Modified: 2010-05-02
Hi, I'm writing code for standard "View" menu, such as "Copy", "Cut", "Paste" and so on. Before performing these operations, I need to check the type of active control. For example, "Cut", "Copy" and "Paste" actions should not been apply on a checkbox, button, and some other control types. What I'm trying now is as follow:

Dim ctrl as Control
Set ctrl = Screen.ActiveControl

If (TypeOf ctrl Is CheckBox) Or (TypeOf ctrl Is CommandButton) Or (...) Or (...) Then
  mnuCopy.Enabled = False
End If

So is there any faster way to check the compatibility between actions (Copy, Paste, ..) with the control type.

Thanks!
 
0
Comment
Question by:lenzge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 7

Expert Comment

by:OHDev2004
ID: 10927144
well if your going to use Cut ,Copy,Paste for certain objects or for specific objects then you can do the following instead of checking trough all available objects :

Dim ctrl as Control
Set ctrl = Screen.ActiveControl

If (TypeOf ctrl Is TextBox) Or (TypeOf ctrl Is RichTextBox) Then
  mnuCopy.Enabled = False
End If

this will let you use your cut,copy,paste ONLY! with the textbox and the richtextbox
Hope i understood you clearly :P
OHDev2004
0
 

Author Comment

by:lenzge
ID: 10937075
I think I understand what you mean. If my application only uses few types of control, then your suggestion will do it. But when there are many types, let says 10 or more, then the number of type checking wil increased accordingly. I need a more general checking way, which can be apply on any project without worrying the type of used control.
0
 
LVL 7

Accepted Solution

by:
OHDev2004 earned 320 total points
ID: 10938231
ok ,, here is a very neat trick :P
every control in vb has properties ,,
there is a property in each control which is called "tag"
so each control you want the user to be able to copy/cut/paste with that control you simply give its tag a key a specific code like the word "Lenzge"

then in the code :

Dim ctrl as Control
Set ctrl = Screen.ActiveControl

If ctrl.tag <> "Lenzge" Then
  mnuCopy.Enabled = False
End If

this will permit the actions only to the controls which share the word Lenzge in their tag
:) hope this is a good one , i usually use it with graphic interfaces ,,
OHDev2004
0
 

Author Comment

by:lenzge
ID: 10956390
Urm... this trick works. Thanks!
0
 
LVL 7

Expert Comment

by:OHDev2004
ID: 10957402
lol ,, Ur welcome
OHDev2004
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question