473,396 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

reference

I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please

Nov 16 '05 #1
6 4631
In article <45**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please


You're calling sr in cmbox1_SelectedIndexChanged, but you declared it in
public void Form1_Load(object sender, System.EventArgs e) which is
outside of the scope of cmbox1_SelectedIndexChanged. In order to fix
that, do the following:

private StreamReader sr;
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
sr = new StreamReader(path);
}

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}

Hope this helps.
Nov 16 '05 #2
Hi Freddy,

You can also do this:

private void Form1_Load(object sender, System.EventArgs e)
{
string path = @"C:\temp\football.txt";
StreamReader sr = new StreamReader(path);
while (sr.Peek()>=0)
{
cbo1.Items.Add(sr.ReadLine());
}
cbo1.SelectedItem =0;
sr.Close();
}

Hope it helps. :)
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <45**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please


You're calling sr in cmbox1_SelectedIndexChanged, but you declared it in
public void Form1_Load(object sender, System.EventArgs e) which is
outside of the scope of cmbox1_SelectedIndexChanged. In order to fix
that, do the following:

private StreamReader sr;
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
sr = new StreamReader(path);
}

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}

Hope this helps.

Nov 16 '05 #3
Hi again,

I forget this:

are you missing a using directive or an assembly reference?)
--> please code this at the top of the code:

using System.IO;

Thanks.
--
Regards,
Chua Wen Ching :)
"Chua Wen Ching" wrote:
Hi Freddy,

You can also do this:

private void Form1_Load(object sender, System.EventArgs e)
{
string path = @"C:\temp\football.txt";
StreamReader sr = new StreamReader(path);
while (sr.Peek()>=0)
{
cbo1.Items.Add(sr.ReadLine());
}
cbo1.SelectedItem =0;
sr.Close();
}

Hope it helps. :)
--
Regards,
Chua Wen Ching :)
"Pollux" wrote:
In article <45**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please


You're calling sr in cmbox1_SelectedIndexChanged, but you declared it in
public void Form1_Load(object sender, System.EventArgs e) which is
outside of the scope of cmbox1_SelectedIndexChanged. In order to fix
that, do the following:

private StreamReader sr;
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
sr = new StreamReader(path);
}

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}

Hope this helps.

Nov 16 '05 #4
I tried it and it build,but nothing is added to the combobox items

"Pollux" wrote:
In article <45**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please


You're calling sr in cmbox1_SelectedIndexChanged, but you declared it in
public void Form1_Load(object sender, System.EventArgs e) which is
outside of the scope of cmbox1_SelectedIndexChanged. In order to fix
that, do the following:

private StreamReader sr;
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
sr = new StreamReader(path);
}

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}

Hope this helps.

Nov 16 '05 #5
Hi freddy,

Can you try the solution i provided to you earlier? It works fine on my computer.

Windows XP Professional SP1
Visual Studio .NET 2003 EA
..NET Framework 1.1

Please make sure your football.txt contains something in there!

Please keep me updated! Thanks.
--
Regards,
Chua Wen Ching :)
"freddy" wrote:
I tried it and it build,but nothing is added to the combobox items

"Pollux" wrote:
In article <45**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I would like to load a path to a file when the form loads like this:
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader (sr) = new StreamReader(path);
}

and when a combobox loads it fills the items with what evers in the file like this:

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}
the problem is when I go to run the project it gives me an error:
G:\Freddy\vb.net\c#\football pool\Football Pool\Form1.cs(1093): The type or namespace name 'sr' could not be found (are you missing a using directive or an assembly reference?)

Help me please


You're calling sr in cmbox1_SelectedIndexChanged, but you declared it in
public void Form1_Load(object sender, System.EventArgs e) which is
outside of the scope of cmbox1_SelectedIndexChanged. In order to fix
that, do the following:

private StreamReader sr;
public void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
sr = new StreamReader(path);
}

private void cmbox1_SelectedIndexChanged(object sender, System.EventArgs
e)
{
while (sr.Peek()>=0) {cbo1.Items.Add(sr.Readline ());}
cbo1.SelectedItem =0;
}

Hope this helps.

Nov 16 '05 #6
In article <FE**********************************@microsoft.co m>,
fr****@discussions.microsoft.com says...
I tried it and it build,but nothing is added to the combobox items


My Understanding is that you're simply trying to add the contents of the
file to the combobox right? You should do this in Form1_Load. It would
looks something like this:

private void Form1_Load(object sender, System.EventArgs e)
{
string path = "G:\\\\Freddy\\vb.net\\c#\\football.txt";
StreamReader sr = new StreamReader(path);
while (sr.Peek()>=0)
cbo1.Items.Add(sr.ReadLine ());
sr.Close();
}

Don't forget to close sr when you don't use it anymore. The other
function you've used should only be called when you want to perform an
action on the element in the combobox you've selected.

Hope this helps.
Nov 16 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: RU | last post by:
Hi, I am working on a porting project to port C/C++ application from unixware C++, AT&T Standard components to g++ with STL on Linux. This application has been working properly on...
110
by: Mr A | last post by:
Hi! I've been thinking about passing parameteras using references instead of pointers in order to emphasize that the parameter must be an object. Exemple: void func(Objec& object); //object...
11
by: Doug | last post by:
Is there any harm in passing an object into a method with the 'ref' keyword if the object is already a reference variable? If not, is there any benefit?
13
by: Abe Frohnman | last post by:
Hello all, I'm passing a reference to a class into the constructor of a form, like so: public MyForm(int count, ref Area myArea) {...} How can I use myArea outside the constructor? Should I...
4
by: z_learning_tester | last post by:
I'm reading the MS press C# book and there seems to be a contradiction. Please tell me which one is correct, 1 or 2. Thanks! Jeff 1. First it gives the code below saying that it prints 0 then...
13
by: al.cpwn | last post by:
I get that these two are different int* get() { static int m; return &m; } int& get() {
51
by: Kuku | last post by:
What is the difference between a reference and a pointer?
27
by: David W | last post by:
I'm almost tearing my hair out. A colleague claimed that a null reference can exist, like this: void f( int& p ) { printf( "%d\n", p ); } int main (int argc, char *argv) {
41
by: Summercool | last post by:
Can we confirm the following? also someone said, Java also has "reference" like in C++, which is an "implicit pointer": Pointer and Reference --------------------- I am starting to see what...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.