Solved

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

Posted on 2004-04-27
5
245 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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now