Men det resulterer bare i at der kommer 3 msgboxes op efter hinanden med forskellige tal (ikke gennemskuelig og mistænker det er fordi at beregningerne ikke er færdig)
I dette særtema om aspekter af AI ser vi på skiftet fra sprogmodeller til AI-agenter, og hvordan virksomheder kan navigere i spændet mellem teknologisk hastighed og behovet for menneskelig kontrol.
Den her fik jeg til at virker.... viser tiden i TT:MM:SS
Sub tid() Dim StartTime As Date, EndTime As Date StartTime = Now() 'alt andet kode EndTime = Now() MsgBox Format(EndTime - StartTime, "hh:mm:ss") End Sub
hmmm... ja, koden hjalp - men nu får jeg bare klokkeslet i første popup og i næste popup får jeg så tiden i sekunder, dog inkl. den tid der tager mig og trykke OK til første Popup.
Det jeg helt specifikt gerne vil have er en funktion - som i sekunder og hundrededele sekunder fortæller hvor lang tid det tager og køre en given funktion. Dvs. et slags spedometer for en tilfældig kode :)
Synes godt om
Slettet bruger
05. juli 2010 - 16:14#7
Kan du ikke læse engelsk, eller hvad er grunden til at du tilsyneladende ikke interesserer dig for det link jeg angav i "2?
Nu fik jeg din (newbieatphp) kode til at virke - problemet er at jeg nok skal bruge en som kan måle under et sekund. Men hvis der ikke kommer andre løsninger får du pointene :)
Dog så kan jeg ikke få den nøjagtige løsning til at virke. For ved ikke hvad det specifikt menes med "call it CTimer say, then you can make an instance somewhere global and just call .StartCounter and .TimeElapsed" og nej det er ikke fordi jeg ikke forstår engelsk :)
Synes godt om
Slettet bruger
06. juli 2010 - 20:41#10
Jeg håber ikke det er ulovligt det her, men nu gør jeg det altså, nemlig kopierer koden fra den artikel jeg linkede til. Det havde jeg regnet med du selv kunne have fundet ud af.
Sub RangeTimer() DoCalcTimer 1 End Sub Sub SheetTimer() DoCalcTimer 2 End Sub Sub RecalcTimer() DoCalcTimer 3 End Sub Sub FullcalcTimer() DoCalcTimer 4 End Sub
Sub DoCalcTimer(jMethod As Long) Dim dTime As Double Dim dOvhd As Double Dim oRng As Range Dim oCell As Range Dim oArrRange As Range Dim sCalcType As String Dim lCalcSave As Long Dim bIterSave As Boolean ' On Error GoTo Errhandl
' Initialize dTime = MicroTimer
' Save calculation settings. lCalcSave = Application.Calculation bIterSave = Application.Iteration If Application.Calculation <> xlCalculationManual Then Application.Calculation = xlCalculationManual End If Select Case jMethod Case 1
' Switch off iteration.
If Application.Iteration <> False Then Application.Iteration = False End if
' Max is used range.
If Selection.Count > 1000 Then Set oRng = Intersect(Selection, Selection.Parent.UsedRange) Else Set oRng = Selection End If
' Include array cells outside selection.
For Each oCell In oRng If oCell.HasArray Then If oArrRange Is Nothing Then Set oArrRange = oCell.CurrentArray End If If Intersect(oCell, oArrRange) Is Nothing Then Set oArrRange = oCell.CurrentArray Set oRng = Union(oRng, oArrRange) End If End If Next oCell
sCalcType = "Calculate " & CStr(oRng.Count) & _ " Cell(s) in Selected Range: " Case 2 sCalcType = "Recalculate Sheet " & ActiveSheet.Name & ": " Case 3 sCalcType = "Recalculate open workbooks: " Case 4 sCalcType = "Full Calculate open workbooks: " End Select
' Get start time. dTime = MicroTimer Select Case jMethod Case 1 If Val(Application.Version) >= 12 Then oRng.CalculateRowMajorOrder Else oRng.Calculate End If Case 2 ActiveSheet.Calculate Case 3 Application.Calculate Case 4 Application.CalculateFull End Select
' Restore calculation settings. If Application.Calculation <> lCalcSave Then Application.Calculation = lCalcSave End If If Application.Iteration <> bIterSave Then Application.Calculation = bIterSave End If Exit Sub Errhandl: On Error GoTo 0 MsgBox "Unable to Calculate " & sCalcType, _ vbOKOnly + vbCritical, "CalcTimer" GoTo Finish End Sub
To find bottlenecks using the drill-down approach 1.Ensure that you have only one workbook open and no other tasks are running.
2.Set calculation to manual.
3.Make a backup copy of the workbook.
4.Open the workbook that contains the Calculation Timers macros, or add them to the workbook.
5.Check the used range by pressing CTRL+END on each worksheet in turn.
This shows where the last used cell is. If this is beyond where you expect it to be, consider deleting the excess columns and rows and saving the workbook. For more information, see the Minimizing the Used Range section of this article.
6.Run the FullCalcTimer macro.
The time to calculate all the formulas in the workbook is usually the worst-case time.
7.Run the RecalcTimer macro.
A recalculation immediately after a full calculation usually gives you the best-case time.
8.Calculate workbook volatility as the ratio of recalculation time to full calculation time.
This measures the extent to which volatile formulas and the evaluation of the calculation chain are bottlenecks.
9.Run the SheetTimer macro on each worksheet in turn.
Because you just recalculated the workbook, this gives you the recalculate time for each worksheet. This should enable you to determine which ones are the problem worksheets.
10.Run the RangeTimer macro on selected blocks of formulas.
1.For each problem worksheet, divide the columns or rows into a small number of blocks.
2.Select each block in turn, and then run the RangeTimer macro on the block.
3.If necessary, drill down further by subdividing each block into a smaller number of blocks.
Men vil den funktion ikke bare finde tiden for en beregning? ikke en kørsel af en kode.
Selvom mit engelske er godt er mit VBA ikke godt :)
Synes godt om
Slettet bruger
07. juli 2010 - 06:34#12
Det har du ret i. Men når du har brug for nøjagtigheder mindre end ét sekund og du ikke er god til VBA, så jeg ved jeg ikke rigtig hvad der kan være til hjælp. Du kan eventuelt prøve at se her:
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.