Jump to content

Problem with Streamwriter

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
noxrawr

noxrawr

    Newbie

  • Members
  • PipPip
  • 23 posts
 static void Main(string[] args)
        {
            RegistryKey rk = Registry.CurrentUser;
            RegistryKey sk1 = rk.OpenSubKey(@"software\\microsoft\\internet explorer\\typedurls");
            Class1 count = new Class1();
            count.countnr();
            int checkvalue = count.countnr();
            
            string[] keys = new string[checkvalue];
            
            
            for (int i = 0; i < checkvalue; i++)
            {
                string inputvalue = "url" + i.ToString();
                keys[i] = (string)sk1.GetValue(inputvalue);
                
                
              
                
            }
            foreach (string s in keys)
            {
                TextWriter str = new StreamWriter(@"c:\urlvalue.txt");
                str.WriteLine(s);
                str.Close();
            }
            
        }

Edit: i figured out the problem I had at first, however a new problem arose.

As you can see I use this in my for iteration

for (int i = 0; i < checkvalue; i++)
            {
                string inputvalue = "url" + i.ToString();
                keys[i] = (string)sk1.GetValue(inputvalue);
                
                
              
                
            }

checkvalue is the total amount of keys listed in the registry.
However when i change i <= checkvalue i get a runtime error, but the thing is, by using i < checkvalue i do NOT get a runtime error but the last value isnt listed.
Any ideas?

Edited by noxrawr, 03 June 2010 - 01:07 AM.


#2
QuackWare

QuackWare

    Learning Programmer

  • Members
  • PipPipPip
  • 95 posts
Do you get a value when i = 0 that you insert into keys[0]?

If not then consider doing (i + 1).toString() in the loop that way it will have all the values.

#3
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
here is a general rule,
when u start a iteration at 0 end them at MAX-1
if started from 1 end them when , value <= MAX.
Your code is perfectly correct ,seems to be some other problem.
Could u post the Exception you get / Run time error that the application throws at you.