Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6976545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:39+00:00 2026-05-27T17:30:39+00:00

Calling a unique function based on matrix row and col index There are three

  • 0

Calling a unique function based on matrix row and col index

There are three views

ViewA
ViewB
ViewC

a user can switch from ViewX to ViewY. There is a different way to switch from X and Y. e.g. Switching from A to B is through one way while from B to A will be through some different way.

I am trying to write a generic function for it. As I can understand, these three views makes a total of 6 combinations (A-B, A-C, B-A, B-C, C-A, C-B)

           ViewA    ViewB   ViewC
    ViewA    X         2        3
    ViewB    4         X        6
    ViewC    7         8        X

What I am thinking that I will register specific function to given move. e.g. if move is from ViewA to ViewB then I will register function SwitchViewA_to_viewB() to the 2nd index.

Please let me know if we can have some other better approach to achive it. This is just an example with three view. In my actual case, I have almost 10 such views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T17:30:39+00:00Added an answer on May 27, 2026 at 5:30 pm

    It’s called a dispatch table.

    my %switchers = (
       ViewA => { ViewB => \&SwitchViewA_to_viewB,
                  ViewC => \&SwitchViewA_to_viewC, },
       ViewB => { ViewA => \&SwitchViewB_to_viewA,
                  ViewC => \&SwitchViewB_to_viewC, },
       ViewC => { ViewA => \&SwitchViewC_to_viewA,
                  ViewB => \&SwitchViewC_to_viewB, },
    );
    
    $switchers{$from}{$to}->()
       if $from ne $to;
    

    or

    my %switchers = (
       "ViewA-ViewB" => \&SwitchViewA_to_viewB,
       "ViewA-ViewC" => \&SwitchViewA_to_viewC,
       "ViewB-ViewA" => \&SwitchViewB_to_viewA,
       "ViewB-ViewC" => \&SwitchViewB_to_viewC,
       "ViewC-ViewA" => \&SwitchViewC_to_viewA,
       "ViewC-ViewB" => \&SwitchViewC_to_viewB,
    );
    
    $switchers{"$from-$to"}->()
       if $from ne $to;
    

    Note that you can pass arguments to the function by passing them within the parens (as usual).


    If you have 10 views, that means to say you have 90 functions.

    Are you sure that’s the way to you want to approach this issue? You should perhaps consider an approach that doesn’t require knowing the previous view. Perhaps you can have two functions per view. One that’s called to activate the view, and another to deactivate it.

    Then you only need to 20 functions instead of 90. And adding an eleventh view would only require writing 2 functions instead of 20.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When calling a function from a page in javascript, is there a way to
I can get the unique id like className@2345 of my object by calling its
Yes, I know you need a unique resource id when calling the version of
Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function
Calling all C macro gurus... Is there any way to write a C macro
Calling Html.RenderPartial(~/Views/Payments/MyControl.ascx); from a view works if MyControl.ascx is a control that directly inherits
I wrote a function that takes 2 parameters , but calling the function with
To delete a document on Lucene, there is the function indexWriter.deleteDocuments(...) with Query and/or
Calling TextRenderer.MeasureText as follows: TextRenderer.MeasureText(myControl.Text, myControl.Font); and comparing the result to the size of
Calling image = Image.open(data) image.thumbnail((36,36), Image.NEAREST) will maintain the aspect ratio. But I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.