Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Never ending loop?

timer innerHTML loop

  • Please log in to reply
11 replies to this topic

#1 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 01 March 2012 - 07:32 PM

So... I am developing a program that snatches matches from the Scrabble database (Words with friends helper basically...), mostly for educational reasons.

But I get stuck in a loop.
Here is my code:
timerwrk = true;
                label3.Text = "Loaded...Working";
                String doc = BROWSER.Document.GetElementById("dictionary").InnerHtml.ToLower();
                //MessageBox.Show(doc);
                String[] add = Regex.Split(doc,"<P>");
                label2.Text = "Matches: " + (add.Length-2).ToString();//-1 because there will be one extra [

                //STOPS RIGHT HERE... MESSAGEBOX DOESNT HAPPEN. JUST PUT FOR DEBUG REASONS

                MessageBox.Show(StringInbetween(add[0], "<b>", "</b>"));

                LV.Items.Clear();
                for (int i = 0; i < add.Length; i++ )
                {
                    String res = StringInbetween(add[i], "<b>", "</b>");
                    MessageBox.Show(res);
                    LV.Items.Add(res);
                }
                timerwrk = false;
                label3.Text = "Done. Got Matches.";

I put in comments where it stops.
Hopefully more eyes will help me figure out whats wrong.

BTW. I have this running as well (might have something to do with it? Dunno... Wont hurt though):
private void timer1_Tick(object sender, EventArgs e)
        {
            if (timerwrk)
            {
                label3.Text = "Loaded...Working";
                if (tm > 3 || tm < 0)
                {
                    tm = 0;
                }
                for (int i = 0; i <= tm; i++)
                {
                    label3.Text = label3.Text + ".";
                }
                tm++;
            }
        }

  • 0

#2 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 01 March 2012 - 08:15 PM

Post the StringInbetween code, as that is what appears to be stopping.
  • 0

#3 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 01 March 2012 - 08:59 PM

public static String StringInbetween(String source, String start, String end)

        {

            int iStart = source.IndexOf(start);

            int iEnd = source.IndexOf(end);

            return source.Substring(iStart,iStart-iEnd-1);

        }

  • 0

#4 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 02 March 2012 - 12:54 AM

Are you absolutely sure it's stopping right there? You see the "Matches: ..." in label2? When you break your code in the debugger it's pointing at that line?
  • 0

#5 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 04 March 2012 - 02:50 PM

Well the label is stuck saying "Loaded...Working" and then changing the .'s like it should with the timer... so it HAS to be in the loop.
  • 0

#6 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 04 March 2012 - 03:18 PM

String[] add = Regex.Split(doc,"<P>");
Is the line I'd suspect. the < and > characters have special meaning in a Regex and I'd guess it's stuck trying to figure out what you want. Change that to
String[] add = doc.Split("<P>");

  • 0

#7 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 04 March 2012 - 03:52 PM

Oh. Hmm. That's what I get for not researching regex enough I guess.
Ok ill try it out thanks
  • 0

#8 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 05 March 2012 - 02:49 PM

Well that doesn't work.
Error	2	Argument '1': cannot convert from 'string' to 'char[]'	C:\Users\Brandon\Documents\Visual Studio 2008\Projects\ScrabbleSolver\ScrabbleSolver\Form1.cs	51	42	ScrabbleSolver

apparently "<P>" wont work....
Also I did this:
String[] add = doc.Split("<P>".toCharArray());
And, as I thought, it still didnt work (also not what I want anyway, since it splits for each char).
At this point I am about to give up on this tiny endeavor.
  • 0

#9 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 05 March 2012 - 04:19 PM

Can you replace < with < and > with > and then do the split on <P> and then replace < and > back to the appropriate characters later?

doc = doc.Replace("<", "<");
doc = doc.Replace(">",">");
String[] add = doc.Split("<P>");

  • 0

#10 Momerath

Momerath

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 282 posts
  • Programming Language:C, Java, C++, C#, PHP, (Visual) Basic, Python, JavaScript, Perl, Visual Basic .NET, Pascal, Ada, Assembly, Fortran, Scheme
  • Learning:Others

Posted 05 March 2012 - 04:34 PM

Well that doesn't work.

Error	2	Argument '1': cannot convert from 'string' to 'char[]'	C:\Users\Brandon\Documents\Visual Studio 2008\Projects\ScrabbleSolver\ScrabbleSolver\Form1.cs	51	42	ScrabbleSolver

apparently "<P>" wont work....


My bad, I though Split had a single string option now (MS, why doesn't Split have a single string option yet?) Use this:
String[] add = doc.Split(new String[] {"<P>"}, StringSplitOptions.RemoveEmptyEntries);

  • 0

#11 BrandonLayton

BrandonLayton

    CC Newcomer

  • Member
  • PipPip
  • 18 posts

Posted 05 March 2012 - 05:38 PM

@Chili
String[] add = doc.Replace("<","<").Replace(">",">").Split("<P>");
Still returns the same error as before.

@Momerath
Works. But I still seem to get stuck in a loop...
  • 0

#12 chili5

chili5

    CC Mentor

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 3038 posts
  • Programming Language:Java, C#, PHP, JavaScript, Ruby, Transact-SQL
  • Learning:C, Java, C++, C#, PHP, JavaScript, Ruby, Transact-SQL, Assembly, Scheme, Haskell, Others

Posted 05 March 2012 - 05:49 PM


String[] add = doc.Replace("<", "<").Replace(">", ">").Split(new string[] { "<P>" },StringSplitOptions.RemoveEmptyEntries);


  • 0





Also tagged with one or more of these keywords: timer, innerHTML, loop

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download