Solved

set menu to invisible

Posted on 1998-12-10
7
200 Views
Last Modified: 2010-05-03
Hi

I tried the following code

Dim vControl As Control
For Each vControl in Me
   If TypeOf vControl Is Menu Then
      vControl.Visible = False
   End If
Next vControl

without successfull. That was because the last sub-menu's visible property can not be set to false (I think).

Can you tell me how to do the job?
0
Comment
Question by:learn
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
Eklipse earned 50 total points
ID: 1449406
I don't know the reason too.
But I suggest this:
Put On error resume next in the beggining of the procedure like this

Sub MenuHide
On error resume next
Dim vControl As Control
    For Each vControl in Me
       If TypeOf vControl Is Menu Then
          vControl.Visible = False
       End If
    Next vControl
End sub

The problem persist but you solve the problem.

Good Luck
Fer

0
 
LVL 3

Expert Comment

by:Sendoh
ID: 1449407
Hi !
This is because of the parent item had been set to false for "Visible". If you tried to set the sub menuitem (not only last), error msg popup.
Anyway, you solve this problem by many ways,
   1) Ignore the error message by "On error go next".
   2) Create the menu using control array.
   etc.

Hope it'll help you !! ^_^
0
 

Author Comment

by:learn
ID: 1449408
To Sendoh

>>>>>>>>
This is because of the parent item had been set to false for "Visible". If you tried to set the sub menuitem (not only last), error msg popup.
>>>>>>>>

The above is not true! I have tried set invisible one menu be one menu and found that we can set invisible to the sub-menu even its parent menu had been set invisible, but not the last sub-menu.

To Eklipse:

Using "On error resume next" in the code shows VB is not a very good languege....I wish we have a Menu collection and can code like "Menus.Visible = false".

Learn
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 1

Expert Comment

by:Eklipse
ID: 1449409
I'm apologize but I thought that you need a solution.
The solution works.I tried to help you.
You don't like the solution.Well, I understand.
Please reject the 'not very good languege' solution and somebody will help you better.
Every problem accept more than one way to solve it and there are better ones and bad ones.
 PD:Examine the 2) item of Sendoh's comment.Maybe is an approach to a better solution

Good luck and Happy christmas
Fer



0
 

Author Comment

by:learn
ID: 1449410
To  Eklipse:

Thank you very much.
As you may guess that I am learning VB instead of using it to make softwares.
I have also tried your answer and found that is correct. However, if you don't mind, I would like to wait for a few days to see if there is any better solusion.

Merry Xmas.

To Sendoh:
 
Can you explain more detail on how to "Create the menu using control array"?

Cheers.

Learn
0
 
LVL 3

Expert Comment

by:Sendoh
ID: 1449411
Hi !
The control array method is quite simple.
First of all, when you create the menu, there is this "Index" field on the menu editor. By specifying the same name for all parent menu(the one shown on screen) with different index(normally start at 0 and so on).
Let said you menu as follow:

      File
      ----Test
      ----Test2
      Edit
      ----Edit 1
      ----Edit 2
      Help
      ----About
The main menu item here is "File","Edit" and "Help".
so you just specifiy the control name as the same name let said "MainMenu" and the different index as well (in this case File-0,Edit-1,Help-2).

The when you need to hide all the visile menu(instead of gone through all the menu + submenu) you can just hide the parent menu.

The code as follow:

    Dim i As Integer
   
    For i = 0 To 2
        MainMenu(i).Visible = False
    Next i

Hope it'll suit you !! ^_^
Merry Christmas !!
0
 

Author Comment

by:learn
ID: 1449412
To Eklipse:

Thank you for your answer and comment. You should get the point.

Happy Xmas.

Learn

To Sendoh:

I haven't got time to test your suggestion but it looks very nice. Thank you.
I will post another question, "Question for Sendoh.", with zero pont. I may ask you something related to this original question or may include nothing. If you answer that, you can get 50 points.

Happy Xmas.

Learn
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

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.
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…

810 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