how can i connect progress bar in richtextbox.text for scanning?

poringgunner

Active member
Joined
Feb 23, 2014
Messages
42
Programming Experience
Beginner
please help..

how can i connect the progress bar in text.
i try but it seem it's not working. it takes less than a second for maximum the progress bar..
all i want is like a virus scanner that show the progress of scanning.. somebody can help?

thanks in advance!
 
You can't "connect the progress bar in text". A ProgressBar simply does what you tell it to do. If it's not doing what you want then it's because you're not telling it to do the right thing. As you haven't provided any reasonable explanation of what you actually want to achieve or what you are currently doing, we can't help you. Provide a FULL and CLEAR description of what you want to do and what you are doing, which would include the RELEVANT code.
 
                    for (int a = 0; a < richTextBox1.Lines.Count(); a++)
                    {
                        string[] richarraycom = richTextBox1.Text.Split(' ', '\n');
                        string[] richarraycom2 = richTextBox2.Text.Split(' ', '\n');
                        int progval = richarraycom.Count() + richarraycom2.Count();
                        progressBar1.Maximum = progval;
                        int delete = 0;

                        //comparing module
                        foreach (string c in richTextBox1.Lines[a].Split(' ', '\n'))
                        {
                            foreach (string v in richTextBox2.Lines[a].Split(' ', '\n'))
                            {
                                try
                                {
                                    if (c == v)
                                    {
                                        count1+=1;
                                        richTextBox1.Text = Regex.Replace(richTextBox1.Text, @" Empty Line", "", RegexOptions.Multiline);
                                        richTextBox2.Text = Regex.Replace(richTextBox2.Text, @" Empty Line", "", RegexOptions.Multiline);

                                    }                                    
                                    if (String.IsNullOrWhiteSpace(c) && String.IsNullOrWhiteSpace(v))
                                    {
                                        count1--;
                                    }
                                    if (richTextBox1.Lines[a].Equals("€") && richTextBox2.Lines[a].Equals("€"))
                                    {
                                        delete++;
                                    }
                                    if (richTextBox1.Text.Count() > richTextBox2.Text.Count())
                                    {
                                        count2 = richarraycom.Length;
                                        count1 -= delete;
                                    }
                                    if (richTextBox1.Text.Count() <= richTextBox2.Text.Count())
                                    {
                                        count2 = richarraycom2.Length;
                                        count1 -= delete;
                                    }
                                    progressBar1.Increment(1);
                                }
                                catch (Exception ex)
                                {

                                }

                            }
                            //formula for comparing 2 files
                            if (count1 > count2)
                            {
                                result = count2 / count1 * multip;
                            }
                            else
                            {
                                //1-2
                                result = count1 / count2 * multip;
                            }                            
                        }
                    }
                    panel1.Visible = true;
                    progressBar1.Visible = true;
                    label3.Visible = true;


here is my code..
i making a program that can compare string to string. it's like a anti virus.. but its only for the text file.. i have a browse button where the selected text file can put in the richtextboxes. and scan it to find if the text is the same or not..
 
Last edited by a moderator:
It should be fairly obvious that you can only display progress that you can measure. What is the progress that you want to measure? You need to be able to know the total amount of work that needs to be done and how much has been done. If you don't know those things then how can you tell the user?
 
progress of scanning.. just like anti virus. it will be finished if the scan is complete.. but in my case everytime i click the scan button.. just a few seconds and its complete.. all i want is to show how the progress goes.
 
progress of scanning.. just like anti virus. it will be finished if the scan is complete.. but in my case everytime i click the scan button.. just a few seconds and its complete.. all i want is to show how the progress goes.

That's completely vague and shows that you haven't put sufficient thought into it. What EXACTLY is it that you want to measure or count? Put some thought into it. If you wanted to report the progress of someone running then you would have to know how far they need to run to get to the end and how far they have run up to the current position. What EXACTLY do you want to measure?
 
progress of scanning.. just like anti virus. it will be finished if the scan is complete.. but in my case everytime i click the scan button.. just a few seconds and its complete.. all i want is to show how the progress goes.
That's how fast your computer is ;)

You simply don't have enough data in your textboxes. If I put 100 lines in each, it's fast; if I put 3000 lines in each, it's slow (and the indication more clear (to the extent that it does not seem to give any progress in the first few seconds).
 
i tried to run that. i compare 5 texts in a single run that contains a thousand lines.. it ends up with a single second. i dont know i set the progressbar maximum value to all richtextbox strings.

int progval = richarraycom.Count() + richarraycom2.Count(); progressBar1.Maximum = progval;
 
What's the point in displaying progress for something that happens so quickly anyway? Don't do it just because you can. Do it because it's useful. If it's not useful then don;t do it. Just changing the cursor to an hourglass or equivalent should be quite enough.
 
Back
Top Bottom