CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2010
    Posts
    14

    Question Help with a program

    I'm trying to make this program that will search google using key words provided from a txt file in order to learn how to make various things interact. However, I'm encountering one problem: if I remove the messagebox that says the txt file's values, the program does not work. But while the messagebox is there, it goes through each line in the txt file as it is suppose to. What do I do to get rid of the messagebox but still have the program work correctly?

    This is the code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Threading;
    
    namespace WindowsFormsApplication1
    {
        
        public partial class Form1 : Form
        {
            
            bool entered = false;  
               
            public Form1()
            {
           
                InitializeComponent();
               
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
               
                webBrowser1.Navigate("http://www.google.com/search?hl=en&source=hp&q=f&aq=f&oq=&aqi=g10");    
                    
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                
    
                 FileStream fileStream = null;
                   StreamReader streamReader = null;
                   try
                   {
                       fileStream = new FileStream(@"c:\Users\comp\Desktop\test.txt", FileMode.Open);
                       streamReader = new StreamReader(fileStream);
                       while (true)
                       {
                           string line = streamReader.ReadLine();
                          MessageBox.Show(line);
                          
                           Thread.Sleep(300);
                       
                        webBrowser1.Document.GetElementById("q").SetAttribute("value", line);
                        webBrowser1.Document.GetElementById("btnG").InvokeMember("click");
                       
                           if (string.IsNullOrEmpty(line))
                               break;
                           timer1.Enabled = false;
                       }
                   }
                   finally
                   {
                       if (streamReader != null)
                           streamReader.Close();
                       if (fileStream != null)
                           fileStream.Close();
                   }
            }
    
    
            private void button2_Click(object sender, EventArgs e)
            {
                timer1.Enabled = false;
                
            }
    
            private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
            {
    
                if (entered == false)
                {
                    timer1.Enabled = true;
                
                    entered = true;
                }
            }
    
    
        }
    }
    (it's in visual studio 2008)
    Last edited by thisismyusername2010; January 17th, 2010 at 07:43 PM.

  2. #2
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Help with a program

    What do you mean when you say "the program does not work"? You probably need to be a bit more specific with errors you're getting. Secondly have tried debugging through the application line by line so you can see what's happening? Lastly you format your code better using code tags. It makes it easier for others to read it and perhaps help you.

  3. #3
    Join Date
    Jan 2010
    Posts
    14

    Re: Help with a program

    When I remove the messagebox, then it just types "undefined" in the google search box. I tried to make it display the lines in a label and richtextbox to see if it were just printing too fast to see on the website, but they didn't return any values.

  4. #4
    Join Date
    Jun 2001
    Location
    Melbourne/Aus (C# .Net 4.0)
    Posts
    686

    Re: Help with a program

    Please state in the title of the thread what the problem is. Imagine if everyone here created a thread called "Help with a program" !!
    Rob
    -
    Ohhhhh.... Old McDonald was dyslexic, E O I O EEEEEEEEEE.......

  5. #5
    Join Date
    Oct 2008
    Location
    Cologne, Germany
    Posts
    756

    Re: Help with a program

    Quote Originally Posted by rliq View Post
    Please state in the title of the thread what the problem is. Imagine if everyone here created a thread called "Help with a program" !!
    you're right every other thread here has alike topic, it's so annoying
    win7 x86, VS 2008 & 2010, C++/CLI, C#, .NET 3.5 & 4.0, VB.NET, VBA... WPF is comming

    remeber to give feedback you think my response deserves recognition? perhaps you may want to click the Rate this post link/button and add to my reputation

    private lessons are not an option so please don't ask for help in private, I won't replay

    if you use Opera and you'd like to have the tab-button functionality for the texteditor take a look at my Opera Tab-UserScirpt; and if you know how to stop firefox from jumping to the next control when you hit tab let me know

  6. #6
    Join Date
    Nov 2002
    Location
    .NET 3.5 VS2008
    Posts
    1,039

    Re: Help with a program

    Quote Originally Posted by thisismyusername2010 View Post
    When I remove the messagebox, then it just types "undefined" in the google search box. I tried to make it display the lines in a label and richtextbox to see if it were just printing too fast to see on the website, but they didn't return any values.
    Have tried running the application through the debugger line by line? That is the quickest and possibly the best to find out where things are going wrong.

  7. #7
    Join Date
    Jan 2010
    Posts
    14

    Re: Help with a program

    everything works fine unless
    Code:
      MessageBox.Show(line);
    is removed, but I need this to be removed for the program to run smoothly

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