Accounting script : Counting months

Recommended Posts

Hi everyone

I am making an accounting script and I am stuck with couting the number of months of each year : example :

I bought a car on : 2000/04/01, this car can be used for 4 years

So I will need to write down the months for each year and count the value's decreasing.

The first year : 9 months (2000)

Second year : 12 months (2001)

Third year : 12 months (2002)

Fourth year : 12 months (2003)

Fifth year : 3 months (2004)

That's an example, so I can't automate the task since I need to count the months for each year from the date I bought the car.

I am not asking you to make the script for me, I already started coding it and spent more than 5 hours trying to solve this using, _dateadd, _datediff ... and other date fonctions

```include <array.au3>
#include <string.au3>
#include <Date.au3>
; Le prix d'achat
\$brut = 50000
; Durée de vie
\$nb_amor = 4
; Taux d'ammortissement
\$taux = 100/\$nb_amor
; Date d'achat
\$d_achat = "2000/2/01"
; Date d'ammortissement totale
; Reprendre les dates exactes
Dim \$date_achat
Dim \$time
_DateTimeSplit(\$d_achat, \$date_achat, \$time)
\$nombre_de_mois = \$nb_amor*12
; Année courante
\$annee_courante = \$date_achat[1]
;travailler sur chaque année
if \$annee_courante = \$date_achat[1] Then
\$diff =_datediff("M",\$d_achat, \$date_achat[1]&\$fin_exercice) +1
ConsoleWrite("Le nombre de mois de la première année " & \$diff)
\$nombre_de_mois -= \$diff
ConsoleWrite(@CRLF & "Le nombre de mois restants est maitenant :" & \$nombre_de_mois & @CRLF)
EndIf```

Until now I did count the number of months for the first year, and the remaining months. But I need to make this automated since I don't know how many years I will be using each time.

Thank you.

Share on other sites

Hi,

Try this :

```\$aDateBuy = StringSplit("2000/04/01", "/") ;date dachat

\$iValidYears = 4 ;pendant combien de temps la voiture peut etre utilisee

For \$iYear = 1 To \$iValidYears - 1 ;1ere annee deja calculee et on calculera a part la derniere annee
ConsoleWrite("year " & \$iYear & " : 12 months (" & \$aDateBuy[1] + \$iYear & ")" & @CRLF)
Next

ConsoleWrite("year " & \$iValidYears & " : " & \$aDateBuy[2] - 1 & " months (" & \$aDateBuy[1] + \$iValidYears & ")" & @CRLF)```

Br, FireFox.

Edited by FireFox
• 1

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

Share on other sites

Thanks a lot that's really what I was looking for

Create an account

Register a new account