Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am counting the time for a movie. When the counting is finished, it increments (linksNumer++;) to the next link in list,and is clicking it. But! Inside linklabel_LinkClicked event, linksNumer gets reseted to the 'i' value (linksNumer = i;) each time.
Basically, it is incrementing in the timer1_Tick event, but in linklabel_LinkClicked event is reseted back to the LAST clicked (with my mouse) link from the list with links on the form1.
I am afraid this code (from Timer event):
LinkLabelLinkClickedEventArgs ex = new LinkLabelLinkClickedEventArgs(ListLinksVisited[linksNumer].Links[0]);
linklabel_LinkClicked(sender, ex);

is not affecting the 'e' from LinkLabelLinkClickedEventArgs From linklabel_LinkClicked event.
I have no idea how to correctly affect it.
More corectly, is affecting the link but then it is reseted again. It loads first 2 links but comes back to the first. It flips from 1,2, back to 1,2 and again to 1,2. Instead of continuing up to 3,4...etc.
Thank you.
Remember, q12.

What I have tried:

C#
int linksNumer = 0;
List<LinkLabel> ListLinksVisited = new List<LinkLabel>();
void linklabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
    if (e.Link.LinkData.ToString() != "")
    {
        Process.Start(e.Link.LinkData.ToString());//opens new link in ma browser
        e.Link.Visited = true; //show in list that link is clicked

        //modify links visited.
        for (int i = 0; i < ListLinksVisited.Count; i++)
        {
            //compare the actual string links
            if (ListLinksVisited[i].Links[0].LinkData.ToString() == e.Link.LinkData.ToString())
            {
                linksNumer = i;
                ListLinksVisited[i].LinkVisited = true;
                ExtractTimeFromLink(ListLinksVisited[i].Text); timer1.Start();
                break;
            }
        }
    }
}

private void timer1_Tick(object sender, EventArgs e)
{
    if (DateTime.Now.Hour == TargetTime.Hour &
        DateTime.Now.Minute == TargetTime.Minute &
        DateTime.Now.Second == TargetTime.Second)
    {
        label1.Text = "done"; timer1.Stop();
        linksNumer++;
        LinkLabelLinkClickedEventArgs ex = new LinkLabelLinkClickedEventArgs(ListLinksVisited[linksNumer].Links[0]);
        linklabel_LinkClicked(sender, ex);
    }

    label1.Update();
}
Posted
Updated 1-Sep-19 5:01am
v3

Without being able to run your code - and we can't - it becomes a combination of guesswork and general advice instead of a solution that we can give.

I'd suspect this line:
C#
if (ListLinksVisited[i].Links[0].LinkData.ToString() == e.Link.LinkData.ToString())
Rather than "not affectinG thE 'e'" - because if that matches, linksNumber is reset as you describe.

So, it's going to be up to you.
Fortunately, you have a tool available to you which will help you find out what is going on: the debugger. If you don't know how to use it then a quick Google for "Visual Studio debugger" should give you the info you need.

Put a breakpoint on the first line in the function, and run your code through the debugger. Then look at your code, and at your data and work out what should happen manually. Then single step each line checking that what you expected to happen is exactly what did. When it isn't, that's when you have a problem, and you can back-track (or run it again and look more closely) to find out why.

Sorry, but we can't do that for you - time for you to learn a new (and very, very useful) skill: debugging!
 
Share this answer
 
Comments
_Q12_ 1-Sep-19 6:07am    
Thank you for your answer mister OriginalGriff. I know all about debugging and without it i couldn't reach so far (as a programmer). It's part of my programming skills, and im doing it automatically at this point. My problem, unfortunately, extends outside the debugging boundaries. My solution is to "minimize" the code in a completely new project,reproduce it, test it, make it cleaner, and hopefully find the problem. I know its a complex issue what i have here, but i still imagining that is a high level of stuff that i dont know yet and must be inserted in my code. I'm afraid is code i dont know, that is too advanced. Some weird method specific for some situation that i have there. That is why i asked this question here. But from your answer it might seem a -logical- problem, like i suspect it myself too and hope to be one. I will comeback with hopefully a cleaner code than what mess i have now.
_Q12_ 1-Sep-19 10:16am    
I will delete this post because its quite weird. I was tired and i get stupid. But the fun fact is that you got it right, very luckily ! - why? because i edited manually some external files that this software was reading from, and there it was a double link that was read (correctly) but way before the expected line. [I] made that mistake in that file. Now when i correct it, it is awesome again and working perfectly. Very lucky that you intuit it, from that comparing line ! Also i listen to your advice to debug it in more depth than i did it previously. So i step into it with way more patience than before. I was rushing it i suppose. What a stupid mistake ! But you did give me great advice ! So, much respect. Live long :) (i hope you can read this before i delete it)
OriginalGriff 1-Sep-19 10:26am    
You're welcome!
 
Share this answer
 
v2
Comments
phil.o 1-Sep-19 12:04pm    
Genuine questions are not meant to be deleted. They can be useful to some other members.
CHill60 2-Sep-19 4:33am    
If you hover over your post the bin icon should appear
_Q12_ 2-Sep-19 6:08am    
thanks @CHill60 , but i see only for the [Solution] i get that delete option. I wanted it for the Main question! There is no such option for us the people. Grrr. But as @phil.o said it, maybe is good for some other members to see what stupidities i wrote (sometimes). hehe

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900