Attribute VB_Name = "mod3Antwoorden"
Option Explicit
' Opdracht 1: breid oefening 3 uit zodat de kolomkoppen: naam, geboortedatum en bedrag worden toegevoegd
Sub Antwoord1()
Dim strBron As String
Dim arrRegel() As String
Dim strRegel As String
Dim r As Integer
strBron = ThisWorkbook.Path & "\Bronnen\Input.csv"
r = r + 1
Cells(r, 1).Value = "Naam"
Cells(r, 2).Value = "Geboortedatum"
Cells(r, 3).Value = "Bedrag"
Open strBron For Input As #1
Do
r = r + 1
Line Input #1, strRegel
arrRegel = Split(strRegel, ",")
Cells(r, 1).Value = arrRegel(0)
Cells(r, 2).Value = converteerDatum(arrRegel(1))
Cells(r, 3).Value = arrRegel(2)
Loop Until EOF(1)
Close #1
End Sub
' Opdracht 2: breid opdracht 1 uit zodat de huidige bedragen in dollars worden geconverteerd naar euro's inclusief het euro-teken
Sub Antwoord2()
Dim strBron As String
Dim arrRegel() As String
Dim strRegel As String
Dim r As Integer
strBron = ThisWorkbook.Path & "\Bronnen\Input.csv"
r = r + 1
Cells(r, 1).Value = "Naam"
Cells(r, 2).Value = "Geboortedatum"
Cells(r, 3).Value = "Bedrag"
Open strBron For Input As #1
Do
r = r + 1
Line Input #1, strRegel
arrRegel = Split(strRegel, ",")
Cells(r, 1).Value = arrRegel(0)
Cells(r, 2).Value = converteerDatum(arrRegel(1))
Cells(r, 3).Value = converteerDollar(arrRegel(2))
Cells(r, 3).Style = "Currency"
Loop Until EOF(1)
Close #1
End Sub
' Opdracht 3: breid opdracht 2 uit met een kolom met de leeftijden
Sub Antwoord3()
Dim strBron As String
Dim arrRegel() As String
Dim strRegel As String
Dim r As Integer
strBron = ThisWorkbook.Path & "\Bronnen\Input.csv"
r = r + 1
Cells(r, 1).Value = "Naam"
Cells(r, 2).Value = "Geboortedatum"
Cells(r, 3).Value = "Bedrag"
Cells(r, 4).Value = "Leeftijd"
Open strBron For Input As #1
Do
r = r + 1
Line Input #1, strRegel
arrRegel = Split(strRegel, ",")
Cells(r, 1).Value = arrRegel(0)
Cells(r, 2).Value = converteerDatum(arrRegel(1))
Cells(r, 3).Value = converteerDollar(arrRegel(2))
Cells(r, 3).Style = "Currency"
Cells(r, 4).Value = berekenLeeftijd(Cells(r, 2))
Loop Until EOF(1)
Close #1
End Sub
' Opdracht 4: breid opdracht 3 uit zodat alle informatie wordt opgeslagen in een output.csv
Sub Antwoord4()
Dim rngBereik As Range
Dim i As Integer
Dim j As Integer
Dim strDoel As String
Dim strRegel As String
Antwoord3
strDoel = ThisWorkbook.Path & "\Bronnen\Output.csv"
Set rngBereik = Range("A1").CurrentRegion
Open strDoel For Output As #1
For i = 1 To rngBereik.Rows.Count
strRegel = ""
For j = 1 To rngBereik.Columns.Count
If strRegel = "" Then
strRegel = Cells(i, j).Value
Else
strRegel = strRegel & ", " & Cells(i, j).Value
End If
Next j
Print #1, strRegel
Next i
Close #1
End Sub
Function berekenLeeftijd(Geboortedatum)
berekenLeeftijd = (Date - Geboortedatum) \ 365.25
End Function
Function converteerDollar(Euro)
converteerDollar = Replace(Euro, ".", ",") * 0.8802
End Function
Download hier het bestand.
