Solved

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

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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.
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 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…

717 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