Accurately reporting on 25% increments of completion

I need a method to report when it's 25%, 50%, 75% & 100% completed.

FullSize = 1387

Obviously there are going to be some decimal places there making this a bit difficult (I've simply used the mod function in the past).

How can I accurately reflect 25% (or as near to it as needed, but not multiple notifications for that marker)?

If (myList.Count / FullList.Count) mod 0 then...
LVL 67
sirbountyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Can you explain a little more about what you're doing?  Is this in a loop or are you checking this at different points?
0
sirbountyAuthor Commented:
Yes, inside a loop.
Very generic.
But for my project, I'm using a for each item in list (of string)
  Add item to new list (if it passes certain validations)

Since it can be a lengthy process, I want to report the percent complete along the way.
0
Kyle AbrahamsSenior .Net DeveloperCommented:
Create 4 bools, set them to false.

dim report25 as Boolean
dim report50 as Boolean

if  (Not report25 AndAlso  Ctype(myList.Count,Decimal) / FullList.Count * 100 >=  25) then
    report25 = true
    Report25() 'or report your number.
else if  (Not report50 AndAlso  Ctype(myList.Count,Decimal) / FullList.Count * 100 >=  50)
    report50 = true
   Report50() ' or report your number
'etc
end if

OR

if you didn't want to report on a threshold just report the number:

lblPercentageComplete.Text = Ctype(MyList.Count, Decimal)/FullList.Count) * 100
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

it_saigeDeveloperCommented:
Quick and dirty method:
Imports System.Runtime.CompilerServices
Module Module1
	Sub Main()
		Dim completed As CompletionPercent = CompletionPercent.Zero
		For i = 0 To 1387
			If Convert.ToInt32((i / 1387) * 100) Mod 25 = 0 AndAlso Convert.ToInt32((i / 1387) * 100) > completed Then
				completed = Convert.ToInt32((i / 1387) * 100)
				Console.WriteLine(String.Format("Completed - {0}", Convert.ToInt32(completed)))
			End If
		Next
		Console.ReadLine()
	End Sub
End Module

Enum CompletionPercent
	Zero = 0
	TwentyFive = 25
	Fifty = 50
	SeventyFive = 75
	OneHundred = 100
End Enum

Open in new window

Produces the following output -Capture.JPG-saige-
0
sirbountyAuthor Commented:
Hmm - wasn't really wanting to add too much complexity to this.
Not trying to over think it here, but really just looking for a brief reporting of where the processing is at, along the way.
So, if the import takes 10 minutes, for example, I was looking for 2 - 3 notifications along the way.  Doesn't have to be 25/50/75/100.  I just used that as it seems to be a good marker for reference.

Like I showed above, when I first began this process, I was getting good round numbers, so it was easy to state simply:
if myList.Count / FullList.count mod .25 = 0 then console.writeline "Import is " & FormatPercent (myList.count / FullList.count, 0) & " completed." (rough memory of how I had it initially setup).

I really wasn't looking at creating multiple booleans for each hard stop, nor otherwise add much additional code.
I do like the enum approach, but is there a simpler way to do this if I don't hold too fast to 25/50/etc?
Perhaps if I just wanted one notification of "halfway there" and a final "All done"?

Thanks for the input though guys - if nothing else, I like the variety of approaches presented. :^)
0
it_saigeDeveloperCommented:
Well let me offer an extension method then:
Module Extensions
	<Extension()> Public Function DisplayProcessPercentage(ByVal currentCount As Integer, ByVal totalCount As Integer, ByVal pageSize As Integer, ByRef currentPercent As Integer) As Boolean
		Dim result As Boolean = False
		Dim tempPercent = ((Convert.ToDouble(currentCount) / Convert.ToDouble(totalCount)) * 100.0F)
		Dim pages = (From value In
		 (From i In Enumerable.Range(0, totalCount) Select ((Convert.ToDouble(i) / Convert.ToDouble(totalCount)) * 100.0F))
		 Group value By Page = If((Int(value) Mod pageSize = 0), Int(value), -1) Into PageGroup = Group
		 Where (Not Page = -1)
		 Select Page, PageGroup)

		Dim currentGroup = (From page In pages Where page.PageGroup.Contains(tempPercent) Select page.PageGroup)
		If tempPercent = 100 Then
			result = True
			currentPercent = tempPercent
		ElseIf currentGroup.Count <> 0 AndAlso currentGroup.ElementAt(0).First.Equals(tempPercent) Then
			result = True
			currentPercent = tempPercent
		Else
			currentPercent = 0
		End If

		Return result
	End Function
End Module

Open in new window

It is hardly perfect but it does get the job done.  For example:
Imports System.Runtime.CompilerServices
Module Module1
	Sub Main()
		Dim value As Integer = 0
		Console.WriteLine("Just some numbers")
		For i = 0 To 1387
			If i.DisplayProcessPercentage(1387, 25, value) Then
				Console.WriteLine(String.Format("Completed - {0}", value))
			End If
		Next

		Console.WriteLine()
		Dim items As New List(Of Integer)
		items.AddRange(Enumerable.Range(1, 148))
		Console.WriteLine("List of 148 items")
		For Each item In items
			If items.IndexOf(item).DisplayProcessPercentage(items.Count - 1, 15, value) Then
				Console.WriteLine(String.Format("Completed - {0}", value))
			End If
		Next
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output:Capture.JPG-saige-
0
Kyle AbrahamsSenior .Net DeveloperCommented:
How about every N records processed?

if mylist.Count mod N = 0 then
  Output(String.Format("{0} out of {1} records processed", myList.Count, FinalList.Count))
end if
0
it_saigeDeveloperCommented:
After tinkering with the extension method some more, I have come up with this edit:
Module Extensions
	<Extension()> Public Function DisplayProcessPercentage(ByVal currentCount As Integer, ByVal totalCount As Integer, ByVal pageSize As Integer, ByRef percent As Integer) As Boolean
		Dim result As Boolean = False
		Dim currentPercent = ((Convert.ToDouble(currentCount) / Convert.ToDouble(totalCount)) * 100.0F)
		Dim pages = (From value In
		 (From i In Enumerable.Range(0, totalCount) Select ((Convert.ToDouble(i) / Convert.ToDouble(totalCount)) * 100.0F))
		 Group value By Page = If((Int(value) Mod pageSize = 0) OrElse ((Convert.ToDouble(totalCount - 1) / Convert.ToDouble(totalCount)) * 100.0F) = value, Int(value), -1) Into PageGroup = Group
		 Where (Not Page = -1)
		 Select PageGroup.First())

		Try
			percent = Int(If(currentPercent.Equals(pages.Last()), 100.0F, (From page In pages Where page.Equals(currentPercent) Select page).First()))
			result = True
		Catch ex As Exception
			percent = -1
			result = False
		End Try

		Return result
	End Function
End Module

Open in new window

Example usage -
Module Module1
	Sub Main()
		Dim value As Integer = 0
		Console.WriteLine("Just some numbers")
		For i = 0 To 1387
			If i.DisplayProcessPercentage(1387, 25, value) Then
				Console.WriteLine(String.Format("Completed - {0}%", value))
			End If
		Next

		Console.WriteLine()
		Dim items As New List(Of Integer)
		items.AddRange(Enumerable.Range(1, 148))
		Console.WriteLine("List of 148 items")
		For Each item In items
			If items.IndexOf(item).DisplayProcessPercentage(items.Count, 15, value) Then
				Console.WriteLine(String.Format("Completed - {0}%", value))
			End If
		Next
		Console.ReadLine()
	End Sub
End Module

Open in new window

Produces the following output -Capture.JPG-saige-
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sirbountyAuthor Commented:
Thanks gang :^)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.