'psuedo code-esque
Dim fileNames as string() = Directory.GetAllFiles(someFolder) 'Directory.GetAllFiles it isn't exactly right but it's close
pbar.Maximum = fileNames.Length
for each fileName as string in fileNames
ProcessFile(fileName) ''do what you would do that takes so long here
pbar.Incriment(1)
next
pbar.Value = pbar.Maximum 'make sure it goes all the way to the end
For Each line As String in rtb.Lines
' Process Code for text formatting here
pbar.increment(1) ' not sure this is right just showing the idea
Next
pbar.Maximum = rtb.Lines.GetLength(0)
Dim ilp As Integer
For ilp = 0 To rtb.Lines.GetLength(0) - 1
'do formatting
pbar.Value = ilp + 1
Next ilp
'do formatting
rtbText.Text = bibleLBL.Text & " 1" & vbCrLf & vbCrLf & rtbText.Text
rtbText.Find(bibleLBL.Text & " 1", RichTextBoxFinds.None)
rtbText.SelectionAlignment = HorizontalAlignment.Center
rtbText.SelectionFont = New Font("Arial", 22, FontStyle.Bold)
rtbText.SelectionColor = Color.Blue
pbar.Maximum = rtbText.Lines.GetLength(0)
Dim ilp As Integer
For ilp = 0 To rtbText.Lines.GetLength(0) - 1
For Each line As String In rtbText.Lines
If line.Contains(":1") Then
' Do nothing
'scripText.SelectAll()
'scripText.Find(line, RichTextBoxFinds.None)
Else
rtbText.Find(line, RichTextBoxFinds.None)
rtbText.SelectionIndent = 18
End If
Next
pbar.Value = ilp + 1
Next ilp
pbar.Value = 0
Unfortunately, there isn't. Tasks will execute at different rates for any given computer based on CPU speed, memory, and load.vbMarkO said:...isnt there a way to measure the time of an event How it takes to complete its task?
Hmmm. That's interesting. I've never noticed a major slow down in execution time when I use a progress bar versus not using a progress bar. My experience is that it is basically a painless operation. Why do you have the double loop in your code? It looks like your processing over the RTB line times. I think you should be able to do this with one loop. Try:vbMarkO said:I am using the Pbar and I just noticed that it is making the time to format in some cases almost double and on the bigger formats its ridiculous
'do formatting
rtbText.Text = bibleLBL.Text & " 1" & vbCrLf & vbCrLf & rtbText.Text
rtbText.Find(bibleLBL.Text & " 1", RichTextBoxFinds.None)
rtbText.SelectionAlignment = HorizontalAlignment.Center
rtbText.SelectionFont = New Font("Arial", 22, FontStyle.Bold)
rtbText.SelectionColor = Color.Blue
pbar.Maximum = rtbText.Lines.GetLength(0)
For Each line As String In rtbText.Lines
If not line.Contains(":1") Then 'just my personal style, you can keep the other invariant if you like
rtbText.Find(line, RichTextBoxFinds.None)
rtbText.SelectionIndent = 18
End If
pbar.Incriment(1)
Next
pbar.Value = 0
Private Sub UpdatePBar()
Dim x As Single
Dim y As Single
Dim percentage As String = CType((ProgressBar1.Value / ProgressBar1.Maximum * 100), Integer).ToString & "%"
Dim gr As Graphics = ProgressBar1.CreateGraphics
Dim sz As SizeF = gr.MeasureString(percentage, ProgressBar1.Font, ProgressBar1.Width)
x = (ProgressBar1.Width / 2) - (sz.Width / 2)
y = (ProgressBar1.Height / 2) - (sz.Height / 2)
gr.DrawString(percentage, ProgressBar1.Font, Brushes.Black, x, y)
End Sub
'do formatting
rtbText.Text = bibleLBL.Text & " 1" & vbCrLf & vbCrLf & rtbText.Text
rtbText.Find(bibleLBL.Text & " 1", RichTextBoxFinds.None)
rtbText.SelectionAlignment = HorizontalAlignment.Center
rtbText.SelectionFont = New Font("Arial", 22, FontStyle.Bold)
rtbText.SelectionColor = Color.Blue
pbar.Maximum = rtbText.Lines.GetLength(0)
Dim ilp As Integer = 0
For Each line As String In rtbText.Lines
If not line.Contains(":1") Then
rtbText.Find(line, RichTextBoxFinds.None)
rtbText.SelectionIndent = 18
End If
ilp += 1
pbar.Value = ilp ''this would probably be better as a regular for loop.
Next
pbar.Value = 0
I agree. That was my original recomendation (see post #7). I was trying to show that the slow down occured due to the use of nested loops, not becuase the value as being explicitly set instead of using the incriment method -- attempting to help answer VBMarkO, "I dont know why the other made it slow down but it did." I apologize for any confusion I might have cuased. By consensus, post #7 is the code to use.Machaira said:Gets rid of having a variable just to change the ProgressBar.