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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:29:29+00:00 2026-06-02T10:29:29+00:00

I have the following code: public Form1() { InitializeComponent(); string strRadio = Utils.ReadFile(strTemp +

  • 0

I have the following code:

public Form1()
{
    InitializeComponent();


    string strRadio = Utils.ReadFile(strTemp + @"\rstations.txt");
    string[] aRadio = strRadio.Split(new string[] { "#" }, StringSplitOptions.RemoveEmptyEntries);    
    for (int i = 0; i < aRadio.Length; i += 2)
    {
       listBox.Items.Add(aRadio[i]);
    }

}

private void listBox_SelectedIndexChanged(object sender, EventArgs e)
{
    int index = listBox.SelectedIndex;
    MessageBox.Show(aRadio[(index+1)]);
}

Now the error is The name 'aRadio' does not exist in the current context. Which comes from MessageBox.Show(aRadio[(index+1)]);. Do I need to declare the aRadio as public or something? If so, how would this be done?

  • 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-06-02T10:29:30+00:00Added an answer on June 2, 2026 at 10:29 am

    You’re declaring aRadio as a local variable within your constructor. You need to declare it as an instance variable, and just assign it a value within your constructor:

    // TODO: Give this a better name
    private readonly string[] aRadio;
    
    // TODO: Give your form a better name too
    public Form1()
    {
        InitializeComponent();
    
        // TODO: You might want to reconsider reading files in a GUI constructor, too
        // TODO: Use Path.Combine(strTemp, "rstations.txt" instead of concatenation
        string strRadio = Utils.ReadFile(strTemp + @"\rstations.txt");
        aRadio = strRadio.Split(new string[] { "#" },
                                StringSplitOptions.RemoveEmptyEntries);
    
        for (int i = 0; i < aRadio.Length; i += 2)
        {
           listBox.Items.Add(aRadio[i]);
        }
    }
    

    I wouldn’t be surprised if you could do rather better than this approach though, by adding a custom object (or just a KeyValuePair<string, string>) to the list box and binding the display part through properties. That way you could get the selected item rather than the selected index… there’s no need to keep text/value pairs like this.

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

Sidebar

Related Questions

I have following code public class TEST { public static void main(String arg[]){ try
i have the following code: public static void Serialize() { List<string> dirs = FileHelper.GetFilesRecursive(fileDirectoryPath);
I have the following code: public class AppDomainArgs : MarshalByRefObject { public string myString;
I have the following code: public partial class Form1 : Form { public BindingList<Class>
I have following code: public static void ProcessStep(Action action) { //do something here if
I have the following code: public class Foo {} static class Program { [XmlElement(foo)]
I have the following code: public partial class queryTerm : System.Web.UI.UserControl { private static
I have the following code: public virtual void Initialise() { this.AddHeader(SystemContext, this.UserSettings.SystemContext); } public
I have the following code: public List<IWFResourceInstance> FindStepsByType(IWFResource res) { List<IWFResourceInstance> retval = new
I have the following code: public Mainform() { ... // scheduler scheduler.DoWork += new

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.