Show remaining time with a progress bar
amadman114
Member Posts: 36
I have further updated this code so that the time remaining is properly shown in a Minute:Seconds format
I took the time to put it into a codeunit, so hopefully it will be moved into the tips and tricks section where others can benefit from it.
I attached my codeunit, and I also attached my example usage of it. Let me know if you need it in a different format (I'm still new to this!)
-Dan
Normal Codeunit:
Codeunit With example "Parent" codeunit:
I took the time to put it into a codeunit, so hopefully it will be moved into the tips and tricks section where others can benefit from it.
I attached my codeunit, and I also attached my example usage of it. Let me know if you need it in a different format (I'm still new to this!)
-Dan
Normal Codeunit:
OBJECT Codeunit 123456785 RemainingTime
{
OBJECT-PROPERTIES
{
Date=08/11/13;
Time=17:17:05;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
VAR
ElapsedTime@1000000000 : Integer;
RemainingMins@1000000002 : Decimal;
RemainingSeconds@1000000003 : Decimal;
RoundedRemainingMins@1000000004 : Integer;
PROCEDURE RemainingTime@1000000000(ProgressI@1000000001 : Integer;ProgressTotal@1000000002 : Integer;StartTime@1000000000 : Time) TimeLeft : Text[30];
BEGIN
// Created by Dan Steele
// Mibuso user amadman114
ElapsedTime := ROUND(((TIME - StartTime) / 1000),1);
RemainingMins := ROUND((((ElapsedTime / ((ProgressI/ProgressTotal) * 100) * 100)-ElapsedTime)/60),0.1);
RoundedRemainingMins := ROUND(RemainingMins,1,'<');
RemainingSeconds := ROUND(((RemainingMins - RoundedRemainingMins)*0.6)*100,01);
TimeLeft := FORMAT(RoundedRemainingMins)+':'+FORMAT(RemainingSeconds);
//Where ProgressI is the increasing value of the number of records completed ProgressTotal
// is the total number of records and StartTime is the time when the process started.
END;
BEGIN
END.
}
}
Codeunit With example "Parent" codeunit:
OBJECT Codeunit 123456785 RemainingTime
{
OBJECT-PROPERTIES
{
Date=08/11/13;
Time=17:17:05;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
VAR
ElapsedTime@1000000000 : Integer;
RemainingMins@1000000002 : Decimal;
RemainingSeconds@1000000003 : Decimal;
RoundedRemainingMins@1000000004 : Integer;
PROCEDURE RemainingTime@1000000000(ProgressI@1000000001 : Integer;ProgressTotal@1000000002 : Integer;StartTime@1000000000 : Time) TimeLeft : Text[30];
BEGIN
// Created by Dan Steele
// Mibuso user amadman114
ElapsedTime := ROUND(((TIME - StartTime) / 1000),1);
RemainingMins := ROUND((((ElapsedTime / ((ProgressI/ProgressTotal) * 100) * 100)-ElapsedTime)/60),0.1);
RoundedRemainingMins := ROUND(RemainingMins,1,'<');
RemainingSeconds := ROUND(((RemainingMins - RoundedRemainingMins)*0.6)*100,01);
TimeLeft := FORMAT(RoundedRemainingMins)+':'+FORMAT(RemainingSeconds);
//Where ProgressI is the increasing value of the number of records completed ProgressTotal
// is the total number of records and StartTime is the time when the process started.
END;
BEGIN
END.
}
}
OBJECT Codeunit 123456788 CalcInvAmount
{
OBJECT-PROPERTIES
{
Date=08/11/13;
Time=17:18:58;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
VAR
GrecSalesInvLine@1000000000 : Record 113;
GLastYear@1000000001 : Date;
GrecSalesInvHeader@1000000002 : Record 112;
Total@1000000003 : Decimal;
InvAmount@1000000004 : Decimal;
intProgressI@1000000005 : Integer;
intProgressTotal@1000000006 : Integer;
intProgress@1000000007 : Integer;
diaProgress@1000000008 : Dialog;
timProgress@1000000009 : Time;
UpdateForm@1000000010 : Form 123456784;
ElapsedTime@1000000011 : Integer;
RemainingTime@1000000012 : Text[30];
StartTime@1000000013 : Time;
RemainingMins@1000000014 : Decimal;
RemainingMinsAndone@1000000015 : Decimal;
RoundedRemainingMins@1000000016 : Integer;
GRecRange@1000000017 : Date;
cduRemainingTime@1000000018 : Codeunit 123456785;
TimeLeft@1000000019 : Text[30];
PROCEDURE Update@1000000005(UpdateType@1000000000 : Option);
BEGIN
CASE UpdateType OF
0 : GRecRange := CALCDATE('-1D',TODAY);
1 : GRecRange := CALCDATE('-1W',TODAY);
2 : GRecRange := CALCDATE('-1M',TODAY);
3 : GRecRange := CALCDATE('-1Y',TODAY);
4 : GRecRange := CALCDATE('-2Y',TODAY);
END;
intProgressI := 0;diaProgress.OPEN('#1####\#2####\@3@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@',ElapsedTime,TimeLeft,intProgress);
GrecSalesInvLine.RESET;
GrecSalesInvHeader.RESET;
GrecSalesInvHeader.SETRANGE("Posting Date",GRecRange, TODAY); // Only Updates Records in the last year
intProgressTotal := GrecSalesInvHeader.COUNT;
GrecSalesInvHeader.FINDFIRST;
timProgress := TIME;
StartTime := TIME;
REPEAT
CLEAR(InvAmount);
GrecSalesInvLine.SETRANGE("Document No.",GrecSalesInvHeader."No."); // Creates a loop too look for all instances of the same
// Document No.
REPEAT
InvAmount := InvAmount + GrecSalesInvLine.Amount;
UNTIL GrecSalesInvLine.NEXT = 0;
GrecSalesInvHeader.Amount := InvAmount;
GrecSalesInvHeader.MODIFY;
//Progress bar -----------------
intProgressI := intProgressI + 1;
IF timProgress < TIME - 1000 THEN BEGIN // every second
timProgress := TIME;
intProgress := ROUND(intProgressI / intProgressTotal * 10000,1);
diaProgress.UPDATE;
END;
TimeLeft := cduRemainingTime.RemainingTime(intProgressI,intProgressTotal,StartTime);
ElapsedTime := ROUND(((TIME - StartTime) / 1000),1);
//Progress bar ----------------
UNTIL GrecSalesInvHeader.NEXT = 0;
diaProgress.CLOSE;
END;
BEGIN
{
DJS Nov 2013
}
END.
}
}
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 326 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions