Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-04-27
5
Medium Priority
?
253 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

597 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