Solved

Filtering of menus

Posted on 2012-03-10
8
320 Views
Last Modified: 2012-06-27
Hi,

I'm working on VB6 and there is a sub function where i have encountered "procedure too large" error, reason is I have to filter the respective selections for individual Profile and it's location and it's hostname. In the end the whole code is a huge chunk of Case loops.

There are 3 variables to consider:
1. Profile (15 in total)
2. Location (35 in total)
3. PC hosts-name (35 in total)

And there are 6 menu selections:
1. Home
2. Control
3. Fire
4. Environment
5. Settings
6. Administration

Clicking on the any of the menu will pop up 5~6 selections.
The problem is the selections are filtered by the 3 variables hence the legacy code was something like...

Select Case Profile
      Case "Power"
              Select Case "Location"
                     Case "Home"
                              If hostsname like "abc" Then
                              ......
                              ......
                              ......



I hope experts can advice on how can i stream line the filtering process without over using Case,If Else loops.
0
Comment
Question by:csharp_learner
[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
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 9

Accepted Solution

by:
lojk earned 500 total points
ID: 37706607
The simplest way to reduce the size of the individual sub is to at least split the inner cases to seperate subs and pass all required params to those.

Select Case Profile
      Case "Power"
              DoPowerOptions(Param1, Param2 )
      Case "SomethingElse"

...


Public Sub DoPowerOptions (Param1 as string, Param2 as string)
           Select Case Param1  
                     Case "Location"
                            DoLocationOptions (Param2)

Public Sub DoLocationOptions (ParamCheck as string)
......


Although this is little more than a sticking-plaster solution to what if fundamentally flawed code. You really should rewrite this code as just from here it looks horribly unmanageable.

For example what happens if you need to add another hostname? You recompile the code and republish it? Consider storing some of the options (and the operations required by that option) in a configuration file or database and reading that into your method and using that information to make the decision as to which operation should do what.

If you could post the whole or at least a more detailed section of the code and some more information about what you are actually trying to achieve i might be able to make more suggestions.
0
 

Author Comment

by:csharp_learner
ID: 37708348
Thanks for your reply lojk,

Yes i agree it's managed in a bad way as it was a legacy code and i'm not so proficient in VB.

The code goes somthing like this...

    Case "Fire"
         Select Case Location
             Case Home
                      If HostName = "abc" Then            
                           Select Case Profile
                                 Case "Power", "user1", "user2", "user3", "main1", "main2"
             Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 1", 100, Enabled
            Menu.InsertMenuItemSeperator 1, lLine
            Menu.InsertMenuItemSubMenu 1, lLine, "Menu Selection 2", 1000, Enabled, 2
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 3", 101, Enabled
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 4, 102, Enabled
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 5", 103, Enabled
         
            lLine = 1
            Menu.InsertMenuItemRegular 2, lLine, "Sub Menu Selection 1", 104, Enabled
            Menu.InsertMenuItemRegular 2, lLine, "Sub Menu Selection 2", 105, Enabled

The first case is for the Power menu, second case is for location, the if statement is for the hostname and the last Case is for the profile. The executing of the menu selection is done in another sub function.

I have thought about writing each profile into a configuration file but there are alot of Profiles, locations and hostname to consider...
0
 
LVL 9

Expert Comment

by:lojk
ID: 37709154
Yuk ;-(

You still havent really shown me enough code but to broaden my original answer, how about this..


  Case "Fire"
         Select Case Location
             Case Home
                      If HostName = "abc" Then            
                           Select Case Profile
                                 Case "Power", "user1", "user2", "user3", "main1", "main2"
       DoMenus_Fire_Home_PowerUserandMain()
       ........

Public sub DoMenus_Fire_Home_PowerUserandMain()
      Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 1", 100, Enabled
            Menu.InsertMenuItemSeperator 1, lLine
            Menu.InsertMenuItemSubMenu 1, lLine, "Menu Selection 2", 1000, Enabled, 2
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 3", 101, Enabled
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 4, 102, Enabled
            Menu.InsertMenuItemRegular 1, lLine, "Menu Selection 5", 103, Enabled
         
            lLine = 1
            Menu.InsertMenuItemRegular 2, lLine, "Sub Menu Selection 1", 104, Enabled
            Menu.InsertMenuItemRegular 2, lLine, "Sub Menu Selection 2", 105, Enabled
End Sub


As i said i would split the inner section of each case into seperate subs - this would at least allow the total sub size to reduce but there is no real substitute for just rewriting this mess I'm afraid..
0
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

 
LVL 15

Expert Comment

by:eemit
ID: 37713856
Try to use Collections e.g.:

colProfile - use Profile name as key e.g. "Power"
colLocation - use Location as key e.g. "Home"
colHostsname - use Hostsname as key e.g. "abc"

To add an item to a collection:
colProfile.Add item, key

To retrieve an item from a collection:
colProfile.Item(index)    'as Index use key string that was specified when the item was added
colProfile(index)              'since Item is the default method, you can use the shorthand syntax
0
 

Author Comment

by:csharp_learner
ID: 37728339
lojk: I'll try to compile more of my code and send in later on. It's my company's property hence i really can't show the whole stuff here. I'm avioding to use the sub function method as I have tried it before and there are lots of parameters involved to be passed and passed back in the legacy code hence i gave up on that idea.

eemit: can you eloborate more on how can I use the collection method to lessen the code?

Thanks for the help thus far experts.
0
 
LVL 15

Expert Comment

by:eemit
ID: 37737952
Hi csharp_learner,
You can at least have a separate sub for each of 6 menu selections.
0
 
LVL 47

Expert Comment

by:Martin Liss
ID: 37848034
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

732 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