Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546817
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:17:50+00:00 2026-05-30T09:17:50+00:00

Not strong in math so here is my problem: I am using a progress

  • 0

Not strong in math so here is my problem:

I am using a progress bar to show progress of work performed in background:

Snippet of my code:

            int i = 0;
            int totalFriends = 0;

            foreach (dynamic friend in facebookFriends)
            {
                totalFriends++;
            }

            foreach (dynamic friend in facebookFriends)
            {
                i++;

                var friend = new FacebookFriend
                {
                    FbId = friend["uid"].ToString()
                };

                AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
            }

Now the application does much more than that and here I am only performing a small chunk of work:
So for example before I reached this section the progress bar had value of 7 and after performing the work it has to reach to 20 and I want to update it while doing the work with appropriate values from 7 to 20:

My take on this is the following:

var intiProgressbarValue = 7;
var finalProgressbarvalue = 20;

foreach (dynamic friend in facebookFriends)
{
    i++;
    var friend = new FacebookFriend
                     {
                         FbId = friend["uid"].ToString()
                     };
    AccountFacebookFriendRepository.SaveOrUpdate(accountFriend);
    var calculatedValue = CalculatedValue(initProgressbarValue, finalProgressBarValue,totalFriends, i);
    UpdateProgressBar( calculatedValue);
}
//note that totalFriends can be any number lets say from 0 to 5000
private int CalculatedValue(int initVal, int finalVal, int totalFriends, int currentFriend)
{
    int progressBarVal = 0;
    //** 
       Perform logic so it will return a progress value that is bigger that 7 and smaller that 20 depending on the number of friends and currently updated friend
    **//
    progressBarVal  = 8;//this would be the result of calculation, a value from 8 to 20
    return progressBarVal;
}

Any help greatly appreciated:

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:17:52+00:00Added an answer on May 30, 2026 at 9:17 am

    Try this:

    private int CalculatedValue(int initVal, int finalVal, int totalFriends, int currentFriend)
    {
        initVal++;
        var diff = finalVal - initVal; // 20-8 = 12
        return (diff*(currentFriend+1))/totalFriends + initVal;
    }
    

    This assumes that currentFriend changes from 0 to totalFriends-1, inclusive. For example, if currentFriend = 99 and totalFriends = 300, the answer this function returns is 12, one third through the range of 8..20 (inclusive).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did some tests on pow(exponent) method. Unfortunately, my math skills are not strong
Here is the code: class Root { public static void main(String[] arguments) { int
here my problem, i'm using asp.net for my site, i get a list of
Here is a simple code illustrating the essence of a problem: class test: def
Here is my picking code public static void pick(GL11 gl){ int[] viewport = new
CSS is not my strong suit, and I am not sure what's going on
JavaScript is not my strong point, but then I'm not sure I'm hitting this
Well I know it's not evil just not as pretty in semantics as <strong>
How to Convert an Object(not String),like TreeNode.item, into primitive like int.
i am doing jump search algorithm but it show me that element is not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.