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 581085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:32:30+00:00 2026-05-13T14:32:30+00:00

How do you use the VALUE of an array number as opposed to what

  • 0

How do you use the VALUE of an array number as opposed to what number in the array it is for determining case? In my code:

for (int x = 0; x < 3; x++)
        {
            switch (position[x])
            {
                case 0:
                    label1.Text = people[x];
                    break;
                case 1:
                    label2.Text = people[x];
                    break;
                case 2:
                    label3.Text = people[x];
                    break;
            }
        }

When this is run, it uses the x in position[] as opposed to position[x]’s value for determining which case to use. For instance, when x is 0, but position[x]’s value is 1, it uses case 0. How do I get the value instead?

EDIT: My code was indeed the problem…. For some reason debugging early in the morning has the effect of creating false images… 😛 As an FYI, here was the correct code…

for (int x = 0; x < 3; x++)
        {
            if (position[x] == 2)
            {
                position[x] = 0;
            }

            else
            position[x]++;

        }

        for (int x = 0; x < 3; x++)
        {
            int val = position[x];
            switch (val)
            {
                case 0:
                    label1.Text = people[x];
                    break;
                case 1:
                    label2.Text = people[x];
                    break;
                case 2:
                    label3.Text = people[x];
                    break;
            }

In the upper first appearance of position[x], I instead had placed only x. Thanks for all the help!

  • 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-13T14:32:30+00:00Added an answer on May 13, 2026 at 2:32 pm

    Try this:

        for (int x = 0; x < 3; x++)
        {
            int val = position[x];
            switch (val)
            {
                case 0:
                    label1.Text = people[x];
                    break;
                case 1:
                    label2.Text = people[x];
                    break;
                case 2:
                    label3.Text = people[x];
                    break;
            }
        }
    

    Maybe something easier would be to say:

    for(int x = 0; x < 3; x++)
    {
        Label label = MyForm.ActiveForm.Controls["label" + position[x]] as Label;
        if (label != null) label.Text = people[x];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use HEX number to assign a value to an int: int
Why can't I use variable which contains a number to specify an array value:
I'm attempting to dynamically use a value in an array within an object. In
How can I use the counter value to multiply the frogs in the array?
Usually when I need to find the max value of an array I use
If I want to add a value in an array, I can use: $array[]
I use the followings to check the array or List is Included a value:
Use PHP and MySQL. I have an array, P, which contains the value of
When I use JQuery's autocomplete and hardcode the array values in the page it
I want to take an array and use that array's values to populate an

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.