CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 19

Threaded View

  1. #5
    Join Date
    Mar 2012
    Posts
    14

    Re: Need Help with Parser C#

    When I try to use the Try Catch method the form runs, however it doesn't work. No matter what I type into inputBx nothing will show in the outputBx.
    I'm wanting this to work with the click of a button, but right now the important thing is making sure it actually all works first.
    The exact same thing happens when I use TryGetValue.

    Perhaps you could look at my code as a whole to see if I'm doing something wrong.

    Code:
    //Dictionary Load Button
            private void button1_Click_1(object sender, EventArgs e)
            {
                if (openFileDialog1.ShowDialog() == DialogResult.OK)   //Allows the user to choose the dictionary to load
                
                {
                   Dictionary<string, string> d = new Dictionary<string, string>();
                   using (StreamReader sr = new StreamReader(openFileDialog1.FileName))
    
                   {
                      string line;
                      while ((line = sr.ReadLine()) != null)
                      {
                          string[] splitword = line.Split(',');
                          d.Add(splitword[0], splitword[1]);
    
                          string outputString = null;
                          if (d.TryGetValue(inputBx.Text, out outputString))
                          {
                              // We have found the string
                              outputBx.Text = outputString;
                          }
                          else
                          {
                              // Haven't found it - do something else
                          }
                          
    
                          
                      }
                                  
                   }
                        
                }
            }
    This returns no errors, runs the form, lets me load a text file for the streamreader but it still doesn't work with what I put into the text boxes

    EDIT: Maybe I actually have to do this on a button_click event before it will work. Either way i'm still stuck. I'll admit I'm a starter at c# so I'm still learning "the ropes"
    Last edited by dahrull; March 18th, 2012 at 07:47 AM. Reason: adding more

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured