Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 7th, 2006, 10:16 PM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default can someone help mi ?

Test.js is a file, it contain:

Hello
Hello
Hello
Hello
Hello

This is my code:

I want to read the line then add the 4 "Hello" in my checkedlistbox items whenever the application start.
So, i do a for loop to read the line then add into my checkedlistbox items.

StreamReader readtheline = new StreamReader("C:\\Test2.js");

            //Read the first line of text
            for (int i = 1; i <= 100; i++)
            {
            string line2 = readtheline.ReadLine();
            checkedListBox1.Items.Add(line2);
            }

             readtheline.Close();
}

but when i want to compile it, it appear an error message :


An unhandled exception of type 'System.ArgumentNullException' occurred in system.windows.forms.dll

Additional information: Value cannot be null.

the line which highlighted green.

Thnks...

 
Old August 8th, 2006, 01:12 AM
2V. 2V. is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

look at your test2.js file there must be more then 100 strings

 
Old August 8th, 2006, 01:55 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey thanks.
sorrie to ask ...
got any idea how to check how many strings inside test2.js then do a for loop.

 
Old August 8th, 2006, 03:23 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

solve it .. thnku ..
using while loop instead of for loop..

while ((line2 = readtheline.ReadLine()) != null)
            {
                checkedListBox1.Items.Add(line2);

            }

 
Old August 8th, 2006, 02:11 PM
2V. 2V. is offline
Authorized User
 
Join Date: Aug 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ye. But there is special properties @EndOfStream@:
            while (!readtheline.EndOfStream)
            {
                checkedListBox1.Items.Add(readtheline.ReadLine());
            }
Its more easy to understand such code)
 
Old August 9th, 2006, 09:31 AM
Authorized User
 
Join Date: Jun 2006
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

woO~ thnks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help mi >? g0dchild_85 C# 5 July 4th, 2006 03:13 AM
can someone help mi ? i m quite a newbie ..[xx(] g0dchild_85 ASP.NET 1.0 and 1.1 Basics 4 June 9th, 2006 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.