Android 9, internal storage running full – ‘weird’ calculations

My phone (Nokia 3.1) is running low on storage, which is a little weird, because then i go to settings ->storage space-> Internal shared storage i see the it as in the images below.

As far as i learned back in school 8,0 + 2,9 + 0,14 + 0,1 + 0,09 + 0,86 is 12,09 and not 15.40 馃榾 …

But it gets better: when i now click Photos & Videos it says my Photos (Google Photo Image) takes up 230 MB and Images 632 MB. But when i click on Images i don’t even get images for 100 MB shown.

Does anybody have an idea what’s going on here, or how to free that ghost-occupied storage? I tried SD Maid, but no success…

enter image description here

enter image description here

Calculations with percentage with jQuery

I’ve the following HTML code: https://jsfiddle.net/tnLad51z/

It’s a simple table with:

  • 1 input for the price without tax
  • 2 inputs for the taxes
  • 1 input for the final price with tax

All the variables looks working well but do I use the ideal way to do these type of calculations ?

function updatePriceWithTaxe() {     var total_taxes = 0;     var total_without_taxes = Number($  ('input[name="RAT_Price"]').val());      $  ('input[name="STX_Amount[]"]').each(function() {         total_taxes += Number($  (this).val());     });      // Calculs     total_taxes = total_without_taxes * total_taxes / 100;     total_with_taxes = total_without_taxes + total_taxes;      // Output     console.log(total_with_taxes.toFixed(2));     $  ('input[name="RAT_PriceTaxed"]').prop('readonly', false).val(total_with_taxes.toFixed(2)).prop('readonly', true); } 

Should I need to add some error handling around non-numbers in the tax area?

Actually, a ‘NaN’ shows up in the ‘total’ if I don’t put some number?

How can I make this?

Thanks.

Calculations for trucks

How can I improve my VBA code to run faster?

The issue I’m having is that the For/Next commands are taking ~10 hours to calculate and print all of the data. I cannot turn of calculations because I need the values calculated for every node (check_nodes).

I have 1 sheet (“Rating”) that performs calculations (25) for every check_node (944 nodes) of all check_trucks (38 trucks) so that’s $ 25\times944\times38=896800$ data points that are compiled then printed to different sheets for each of the 38 trucks. The results & format I’m getting are correct I just need to speed up the code somehow.

Originally I was going to run the VBA individually for all 38 trucks but then decided to modify the code to run all trucks automatically. Unfortunately this increased run time dramatically.

Sub Perform_Rating_Check()  Dim StartTime As Double Dim SecondsElapsed As Double  'Remember time when macro starts   StartTime = Timer  '------------------------ 'DETERMINE NUMBER OF ROWS OF DATA FOR LOAD RATING SUMMARY '------------------------      Application.ScreenUpdating = False     Application.DisplayStatusBar = False     Application.EnableEvents = False      Sheets("Output").Activate     Row = Range("Start.Nodes").Row     Column = Range("Start.Nodes").Column      startRow = Range("Start.Nodes").Row     nrows = Range("Num_Checks").Value      ReDim check_nodes(1 To nrows)     For q = 1 To nrows         check_nodes(q) = Cells(startRow - 1 + q, Column)     Next  '------------------------------ 'CALCULATE & PRINT LOAD RATINGS '------------------------------      ReDim PR_summary(1 To nrows, 1 To 26)      Sheets("Rating").Activate     Truck_row = Range("Start.Truck").Row     Truck_col = Range("Start.Truck").Column      ntrucks = Range("Num.Trucks").Value      ReDim check_trucks(1 To ntrucks)     For k = 1 To ntrucks         check_trucks(k) = Cells(Truck_row - 1 + k, Truck_col)     Next      For j = 1 To ntrucks         TruckSheet = check_trucks(j)         Range("Choose.Truck") = check_trucks(j)         Sheets(TruckSheet).Activate              For s = 1 To nrows                 Range("Check_Location") = check_nodes(s)                 PR_row = Range("A9").Row - 1                 PR_col = Range("A9").Column - 1                 Cells(PR_row + s, PR_col + 1) = check_nodes(s)                 Cells(PR_row + s, 2) = Range("RF_INV_Axial").Value                 Cells(PR_row + s, 3) = Range("RF_INV_Major").Value                 Cells(PR_row + s, 4) = Range("RF_INV_Minor").Value                 Cells(PR_row + s, 5) = Range("RF_OPR_Axial").Value                 Cells(PR_row + s, 6) = Range("RF_OPR_Major").Value                 Cells(PR_row + s, 7) = Range("RF_OPR_Minor").Value                 Cells(PR_row + s, 8) = Range("RF_INV_Axial_My").Value                 Cells(PR_row + s, 9) = Range("RF_INV_Major_My").Value                 Cells(PR_row + s, 10) = Range("RF_INV_Minor_My").Value                 Cells(PR_row + s, 11) = Range("RF_OPR_Axial_My").Value                 Cells(PR_row + s, 12) = Range("RF_OPR_Major_My").Value                 Cells(PR_row + s, 13) = Range("RF_OPR_Minor_My").Value                 Cells(PR_row + s, 14) = Range("RF_INV_Axial_Mz").Value                 Cells(PR_row + s, 15) = Range("RF_INV_Major_Mz").Value                 Cells(PR_row + s, 16) = Range("RF_INV_Minor_Mz").Value                 Cells(PR_row + s, 17) = Range("RF_OPR_Axial_Mz").Value                 Cells(PR_row + s, 18) = Range("RF_OPR_Major_Mz").Value                 Cells(PR_row + s, 19) = Range("RF_OPR_Minor_Mz").Value                 Cells(PR_row + s, 20) = Range("RF_INV_Shear_P").Value                 Cells(PR_row + s, 21) = Range("RF_INV_Shear_My").Value                 Cells(PR_row + s, 22) = Range("RF_INV_Shear_Mz").Value                 Cells(PR_row + s, 23) = Range("RF_OPR_Shear_P").Value                 Cells(PR_row + s, 24) = Range("RF_OPR_Shear_My").Value                 Cells(PR_row + s, 25) = Range("RF_OPR_Shear_Mz").Value             Next s     Next j  'Determine how many seconds code took to run   SecondsElapsed = Round(Timer - StartTime, 2)  'Notify user in seconds   MsgBox "This code ran successfully in " & SecondsElapsed & " seconds", vbInformation      Application.ScreenUpdating = True     Application.DisplayStatusBar = True     Application.EnableEvents = True  End Sub 

I like how the data is printed currently but I just want it to run much faster. Last time I ran the code it took about 10 hours to complete.

Wait for calculations within loop to finish before return

I have two components, charValueMatcher and main. The charValueMatcher module accepts a string which it loops through and formats the string. When it’s done, the formatted string is returned. main is simply using this module.

charValueMatcher.js

module.exports = (string) => {   let formatted = [];   let i = 0;   while(i < string.length) {     if (string[i] === 'b') {       formatted.push({'b': 123});     } else {       formatted.push({[string[i]: 456}});     }     i ++;   }   return formatted; } 

main.js

const charValueMatcher = require('./charValueMatcher');  console.log(charValueMatcher('ManyLettersandbitsAndThings')); 

My issue here is that althought it works, in other words charValueMatcher doesn’t return an empty array, but the array of objects produced by the loop, it doesn’t feel very asyncronous to block the return statement with a while loop. How could I improve my code to take advantage of Node’s asyncronous nature?

Google Sheets API call creates scientific numbers that I cannot then run calculations on

I am using API in Google Sheets to call prices of cryptocurrencies vrs Bitcoin from URL: https://api.coinpaprika.com/v1/tickers?quotes=BTC

In some cases I am getting scientific notation instead of the x.xxxxxxxx number value. (e.g. Verge coin price (in bitcoin) is currently pulling in 9.4e-7 instead of 0.00000094)

I cannot then do any formula work on the imported data because it is not converting back to the number, and I have so far found no way to convert it or stop it being imported as a scientific number.

I have tried formatting the import cells to text, but that still pulls the scientific number in from the API call (I have contacted coinpaprika support to see if they know a way around it).

What I need is a way to convert that scientific number into x.xxxxxxxx number format so that I can then use it in a formula to calculate the value (in bitcoin) of my holdings in a particular cryptocurrency.

Automating using spreadsheet for calculations [on hold]

Okay so, I have spreadsheet: https://drive.google.com/file/d/0B0K52-VEkRDTeWI3U3V2LTVVYUk/view Which i would like to use for calculations. This spreadsheet is used for calculating Damage per second on an online rpg. In spreadsheet you can change “gear” or items which your charecter has.

I would like to do calculations quickly for example 20 characters with different items on changing only one specific for all of them. I was thinking i could just make object called character with strings for gear and just use openpyxl to modify string values on spreadsheet but that brought out errors because openpyxl doesn’t do calculations and for some reason even though values (attributes like strength and Attackpower) changed like i wanted all formulas went for DIV/0! error.

Do i need to implement all formulas in some programming language for myself or is there somekind of way to use existing spreadsheet with calculations for my advantage?

I would like to use C/C++, java or python for this project.

Speed up calculations with arrays/dictionaries

I’ve got a large macro which calculates diverse things for my job. I work in a contact center.

Firstly it writes people and forecast data. With this calculates if there are more/less people than it should (depending on the forecast). After this calculation Uses it to calculate the break time for everyone CalculadoraAux.

Once this is all done, the calculation starts(and is the slow block of the code). First for department and then for department and city(this last depends on the department and the number of people working on each city to distribuite things). It calculates for half hours and then 4 totals, grand total, morning, afternoon and night.

Hope I’ve explained myself kind of clearly, but I can answer anything you need to help me speed up this code:

Option Explicit Sub Recalcular(Reforecast As Boolean)      Dim arrAgentes As Variant, wsTD As Worksheet, Comprueba As Boolean, Col As Integer, ColIAux, ColFAux, Reductores As Single, _     LastRow As Long, x As Long, i As Long, C As Range, y As Long, B As Byte, ColI, ColF, wsP As Worksheet, _     wsObj As Worksheet, arrKPI As Variant, arrKPI2 As Variant, A As Long, arrDescansos, _     DictModoDia As Scripting.Dictionary, arrPronosticos, wsPron As Worksheet, wsDescanso As Worksheet, STRUnion As String     Dim Contador      '=========================FROM HERE============================='     Dim DictPronosticos As Scripting.Dictionary     Dim DictHojaPronosticos As Scripting.Dictionary     Dim DictModosDias As Scripting.Dictionary      Set DictPronosticos = New Scripting.Dictionary     Set DictModos = New Scripting.Dictionary     Set DictModoDia = New Scripting.Dictionary     Set DictHojaPronosticos = New Scripting.Dictionary     Set DictModosDias = New Scripting.Dictionary     Set wb = ThisWorkbook     Set ws = wb.Sheets("Programaciones")     Set wsP = wb.Sheets("Servicio")     Set wsObj = wb.Sheets("Objetivos")     Set wsPron = wb.Sheets("Pronosticos")     If Reforecast Then Set wsPron = wb.Sheets("PronosticosReforecast")     With ws         i = .Cells(.Rows.Count, 1).End(xlUp).Row         .Range("E5:BD" & i).ClearContents     End With     Call CrearTablaAgentes 'PivotTable Creation     Set wsTD = wb.Sheets("TablaProgramados")     LastRow = wsTD.Cells(wsTD.Rows.Count, 1).End(xlUp).Row     arrAgentes = wsTD.Range("A2:BC" & LastRow).Value 'Store PivotTable into array      'Dictionary     For i = LBound(arrAgentes) To UBound(arrAgentes)         If arrAgentes(i, 2) = vbNullString Then         ElseIf Not arrAgentes(i, 3) = vbNullString Then             STRUnion = Application.Proper(arrAgentes(i, 3)) & arrAgentes(i, 1) & arrAgentes(i, 2) & "1.Presentes Programados"             DictModosDias.Add STRUnion, i         Else             STRUnion = "ALL" & arrAgentes(i, 1) & Mid(arrAgentes(i, 2), 7, Len(arrAgentes(i, 2))) & "1.Presentes Programados"             DictModosDias.Add STRUnion, i         End If     Next i     Application.DisplayAlerts = False     wsTD.Delete      ColI = Array(5, 21, 37, 5)     ColF = Array(52, 36, 52, 20)     ColIAux = Array(13, 109, 205, 13)     ColFAux = Array(300, 204, 300, 108)      'Dictionary to know positions on some data     For Each C In wsP.Range("C35", wsP.Range("C35").End(xlDown))         If C.Font.Color = 49407 Then             DictPronosticos.Add C.Value, 1         End If     Next C      'Goal Data     With wsObj         LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row + 1         .Rows(LastRow & ":1000").Delete         arrObjetivos = wsObj.UsedRange.Value     End With      'Dictionary to know where the goal positions are     For i = 2 To UBound(arrObjetivos)         DictModos.Add arrObjetivos(i, 2), i     Next i      'Main data to be calculated     With ws         LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row         arrMatriz = .Range("A5:BD" & LastRow).Value     End With      'Dictionary to know the position of each group     Set DictKPIModoDia = New Scripting.Dictionary     For i = 1 To UBound(arrMatriz)         DictKPIModoDia.Add arrMatriz(i, 1) & arrMatriz(i, 2) & arrMatriz(i, 3) & arrMatriz(i, 4), i     Next i      'Data     arrPronosticos = wsPron.UsedRange.Value      'Dictionary to know the position of each group     For i = 2 To UBound(arrPronosticos)         DictHojaPronosticos.Add arrPronosticos(i, 1) & arrPronosticos(i, 2) & arrPronosticos(i, 3) & arrPronosticos(i, 4), i     Next i      Dim Centro As String, Modo As String, Fecha As Date, KPI As String, Centros, Multiplicador As Single, CentroFuncion As String     For i = 1 To UBound(arrMatriz, 1)         'Rellenamos los pron贸sticos         Centro = arrMatriz(i, 1)         Modo = arrMatriz(i, 3)         Fecha = CDate(arrMatriz(i, 2))         KPI = arrMatriz(i, 4)         If DictPronosticos.Exists(KPI) Then             For A = 5 To 56                 If DictHojaPronosticos.Exists(Centro & Fecha & Modo & KPI) Then                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = arrPronosticos(DictHojaPronosticos(Centro & Fecha & Modo & KPI), A)                 Else                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = vbNullString                 End If             Next A         End If     Next i      For i = 1 To UBound(arrMatriz, 1)         Centro = arrMatriz(i, 1)         Modo = arrMatriz(i, 3)         Fecha = CDate(arrMatriz(i, 2))         KPI = arrMatriz(i, 4)         If KPI = "1.Presentes Programados" Then             STRUnion = Centro & Fecha & Modo & KPI             For A = 5 To 56                 On Error Resume Next                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = arrAgentes(DictModosDias(STRUnion), A - 1)                 If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = 0 Then arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = vbNullString                 On Error GoTo 0             Next A         ElseIf KPI = "2.Efectivos" Then             For A = 5 To 52                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = Formulas(Fecha, Modo, KPI, A, i, arrDescansos, _                 DictModoDia, Centro)                 If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = 0 Then arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = vbNullString             Next A             For A = 53 To 56                 ReDim Contador(ColI(A - 53) To ColF(A - 53)) As Double                 On Error Resume Next                 For Col = LBound(Contador) To UBound(Contador)                     Contador(Col) = arrMatriz(i, Col)                 Next Col                 On Error GoTo 0                 arrMatriz(i, A) = Application.Sum(Contador) / 2                 If arrMatriz(i, A) = 0 Then arrMatriz(i, A) = vbNullString             Next A         ElseIf KPI = "94.Sobre/Infra" Then             For A = 5 To 56                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = Formulas(Fecha, Modo, KPI, A, i, arrDescansos, _                 DictModoDia, Centro)             Next A         End If     Next i      ws.Range("A5:BD" & UBound(arrMatriz) + 4) = arrMatriz     Debug.Print Timer & "aux"     Outputs.CalculadoraAux     Debug.Print Timer & "aux"     '=========================TO HERE=============================' Fast Enough      '=========================FROM HERE============================='     wb.Sheets("Mapa Turnos").AutoFilterMode = False     Set wsDescanso = wb.Sheets("Calculadora AUX")     arrDescansos = wsDescanso.UsedRange.Value     wsDescanso.Visible = xlSheetHidden     For i = 2 To UBound(arrDescansos)         If Not DictModoDia.Exists(arrDescansos(i, 1) & arrDescansos(i, 3)) Then             DictModoDia.Add arrDescansos(i, 1) & arrDescansos(i, 3), i         Else             DictModoDia(arrDescansos(i, 1) & arrDescansos(i, 3)) = DictModoDia(arrDescansos(i, 1) & arrDescansos(i, 3)) & ", " & i         End If     Next i     Dim SplitCentros, arrPorcentaje, m As Long, CentroCC As String, DictPorcentajeCentros As Scripting.Dictionary     Set DictPorcentajeCentros = New Scripting.Dictionary     Erase Contador      'Calculate KPIs but the ones already calculated     For i = 1 To UBound(arrMatriz, 1)         Centro = arrMatriz(i, 1)         Modo = arrMatriz(i, 3)         Fecha = CDate(arrMatriz(i, 2))         KPI = arrMatriz(i, 4)         If Centro <> "ALL" And KPI = "1.Presentes Programados" Then  'aqu铆 calculamos directamente las capacidades y el % seg煤n centro para llamadas y req             For A = 5 To 56                 If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A) = 0 And Not A = 56 Then GoTo SiguienteCC                 SplitCentros = Split(wb.Sheets("Servicio").Cells.Find(Modo).Offset(0, 1), "/")                 ReDim arrPorcentaje(0 To UBound(SplitCentros))                 For m = 0 To UBound(SplitCentros) 'Rellenamos Efectivos Finales para poder hacer el c谩lculo a todos                     CentroCC = SplitCentros(m)                     arrMatriz(DictKPIModoDia(CentroCC & Fecha & Modo & "21.Descansos Finales"), A) = _                         Formulas(Fecha, Modo, "21.Descansos Finales", A, i, arrDescansos, DictModoDia, CentroCC)                     arrMatriz(DictKPIModoDia(CentroCC & Fecha & Modo & "22.Efectivos Finales"), A) = _                         Formulas(Fecha, Modo, "22.Efectivos Finales", A, i, arrDescansos, DictModoDia, CentroCC)                 Next m                 For m = 0 To UBound(SplitCentros)                     On Error Resume Next                     arrPorcentaje(m) = _                     (arrMatriz(DictKPIModoDia(SplitCentros(m) & Fecha & Modo & "22.Efectivos Finales"), A) * 1800) / _                     arrMatriz(DictKPIModoDia(SplitCentros(m) & Fecha & Modo & "6.TMO"), A)                     DictPorcentajeCentros.Add SplitCentros(m), m                     On Error GoTo 0                 Next m                 'Porcentaje a aplicar                 On Error Resume Next                 Multiplicador = 0                 Multiplicador = arrPorcentaje(DictPorcentajeCentros(Centro)) / Application.Sum(arrPorcentaje)                 DictPorcentajeCentros.RemoveAll                 'Call Capacity                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "95.Call Capacity"), A) = _                     arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "95.Call Capacity"), A) * Multiplicador                 'Pron贸stico                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A) = Multiplicador * _                     arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "5.Pron贸stico"), A)                 'Call Capacity ajustado                 If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "95.Call Capacity"), A) > _                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A) Then                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "96.Call Capacity ajustado curva"), A) = _                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A)                 Else                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "96.Call Capacity ajustado curva"), A) = _                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "95.Call Capacity"), A)                 End If                 'Requeridos                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "92.Requeridos"), A) = Multiplicador * _                     arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "92.Requeridos"), A)                 'NDA                  arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "3.NA"), A) = Multiplicador * _                     (arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "3.NA"), A) * _                     arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "5.Pron贸stico"), A)) / arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A)                 'NDS                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "4.SL"), A) = Multiplicador * _                     (arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "4.SL"), A) * _                     arrMatriz(DictKPIModoDia("ALL" & Fecha & Modo & "5.Pron贸stico"), A)) / arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A)                 'Descubierto                 If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A) > 0 And _                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "22.Efectivos Finales"), A) = 0 Then _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "93.Descubierto"), A) = "SI"                 'Sobre/Infra                 On Error Resume Next                 arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "94.Sobre/Infra"), A) = _                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "22.Efectivos Finales"), A) - _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "92.Requeridos"), A)                 'Occupancy                 If A < 53 Then                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "97.Occ"), A) = _                         (arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), A) * _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "6.TMO"), A)) / _                         (arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "22.Efectivos Finales"), A) * 1800)                     If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "97.Occ"), A) > 1 Then _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "97.Occ"), A) = 1 'si el occupancy es mayor que 1                 ElseIf A = 56 Then                     KPI = "97.Occ"                     GoTo Totales:                 End If SiguienteCC:             Next A         End If         If KPI = "92.Requeridos" Or KPI = "5.Pron贸stico" Or DictPronosticos.Exists(KPI) Then GoTo SiguienteKPI         If KPI = "1.Presentes Programados" Or KPI = "2.Efectivos" Or Centro = "ALL" And KPI = "94.Sobre/Infra" Then GoTo SiguienteKPI         If Centro <> "ALL" And Not arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), 53) = 0 Then GoTo SiguienteKPI         For A = 5 To 52             arrMatriz(i, A) = Formulas(Fecha, Modo, KPI, A, i, arrDescansos, DictModoDia, Centro)         Next A Totales:         'Totals         For A = 53 To 56             Select Case KPI                 Case "93.Descubierto", "94.Sobre/Infra", "96.Call Capacity ajustado curva"                     arrMatriz(i, A) = Formulas(Fecha, Modo, KPI, A, i, arrDescansos, DictModoDia, Centro)                 Case "3.NA", "4.SL", "97.Occ"                     ReDim arrKPI(ColI(A - 53) To ColF(A - 53))                     ReDim arrKPI2(ColI(A - 53) To ColF(A - 53))                     For Col = ColI(A - 53) To ColF(A - 53)                         arrKPI2(Col) = arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "5.Pron贸stico"), Col)                         arrKPI(Col) = arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), Col)                     Next Col                     On Error Resume Next                     arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) = Application.SumProduct(arrKPI, arrKPI2) / Application.Sum(arrKPI2)                     On Error GoTo 0                     Erase arrKPI                     Erase arrKPI2                     If arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) > 0 And arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & KPI), A) > 1 And Not KPI = "97.Occ" Then arrMatriz(i, A) = 1                 Case "21.Descansos Finales"                     On Error Resume Next                     Reductores = arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "7.Formaci贸n"), A) + _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "9.Ausencias no programadas"), A) + _                         arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "91.Otros"), A)                     On Error GoTo 0                     Contador = Split(DictModoDia(arrMatriz(i, 2) & arrMatriz(i, 3)), ", ")                     If UBound(Contador) = -1 Then                         arrMatriz(i, A) = 0                         GoTo SiguienteKPI                     End If                     With wsDescanso                         arrMatriz(i, A) = (Application.Sum(.Range(.Cells(Contador(0), ColIAux(A - 53)), _                         .Cells(Contador(UBound(Contador)), ColFAux(A - 53)))) * 60) / _                             (Application.Sum(.Range(.Cells(Contador(0), 7), .Cells(Contador(UBound(Contador)), 8))) * 3600)                     End With                     If arrMatriz(i, A) = 0 Then arrMatriz(i, A) = vbNullString                 Case "1.Presentes Programados", "2.Efectivos", "22.Efectivos Finales"                     ReDim Contador(ColI(A - 53) To ColF(A - 53)) As Double                     On Error Resume Next                     For Col = LBound(Contador) To UBound(Contador)                         Contador(Col) = arrMatriz(i, Col)                     Next Col                     On Error GoTo 0                     arrMatriz(i, A) = Application.Sum(Contador) / 2                 Case Else                     ReDim arrKPI(ColI(A - 53) To ColF(A - 53))                     For Col = ColI(A - 53) To ColF(A - 53)                         arrKPI(Col) = arrMatriz(DictKPIModoDia(Centro & Fecha & Modo & "95.Call Capacity"), Col)                     Next Col                     arrMatriz(i, A) = Application.Sum(arrKPI)                     If arrMatriz(i, A) = 0 Then arrMatriz(i, A) = vbNullString                     Erase arrKPI             End Select         Next A  SiguienteKPI:      Next i      '=========================TO HERE=============================' Very slow and time consuming.      'Paste the array back to the worksheet     With ws         .Range("A5:BD" & UBound(arrMatriz) + 4) = arrMatriz     End With  End Sub 

External functions such as CalculadoraAux or Formulas don’t have effect on the executing time.

PS: there might be variables not declared here, but they are global variables (When I first started this I didn’t know that shouldn’t happen…)

“If then” calculations based on value

I have about a dozen tables in a new form that is working perfectly. Tables may contain positive or negative adjustments to static numbers. I need a field to calculate all of the fields that contain negative adjustments and another for positive adjustments.

I imagine some sort of “if then” statement will do this but I am not sure where to start.

Something like this maybe:

=if ChangeAmount <= 0 then ADD  

Object Oriented Approach to Calculations

I need to determine the average miles per hour for a trip and an object containing a list of trips. I’m thinking of two approaches. First approach, have a MphCalculator class that I would inject into each class such as

public class MphCalculator {      public BigDecimal calculateMph(int durationSeconds, BigDecimal miles) {         //calculate speed     }  } 

The second approach would be for each object to have their own reference to an MphCalculator class such as

public class SpeedCalculator {      final int durationSeconds;     final BigDecimal miles;      public SpeedCalculator(int durationSeconds, BigDecimal miles) {         this.durationSeconds = durationSeconds;         this.miles = miles;     }       public BigDecimal calculateMph() {         //calculate and store speed     }  } 

The second approach to me seems more Object Oriented, but it also seems as though I may be creating unnecessary objects. If anyone could provide some pros/cons then that’d be very helpful! Also, this is my first question, so if I could improve this post in any way let me know.