Solved

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

Posted on 2004-04-27
5
248 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
  • 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 80 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

792 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