building a cost control system with Basic-256 (New Features)

Next program is adding the BudgetCode
I use budget codes in the range aaaaa thru zzzzz

Popular ones are:
benzi = petrol for the car
ziek = insurance health, the negative result is tax reductable...
tuin = maintenance garden
autov = insurance of the car
autob = tax for using the car
green = the electricity used from the net and generated by a wind-generator to the net
and so on, we have about 140 Budgets to observe...

I'm using two tables:
1) Account Creditor > budgetcode
2) Description containing budgetcode

The program RekKostToev.kbs does the work:

# Kostenplaats bijzoeken
print (currentdir)

gosub Init
gosub BijzoekenKostenplaats
end

Init: #
Rmax = 100
Tmax = 100
return

print "Credit"
dim RK\$(Rmax, 3)
Credit\$ = "RekNaar_Kosten.csv"
Invoer = 1
open (Invoer, Credit\$)
R = 1
while not eof (Invoer)
Invoer\$ = readline (Invoer)
if length(Invoer\$) > 5 then
Veld\$ = explode(Invoer\$, ",")
print Veld\$[?]
print R+" "+Veld\$[0]+" "+Veld\$[1]
RK\$[R,1] = Veld\$[0]
RK\$[R,2] = Veld\$[1]
R = R + 1
if R > Rmax - 2 then
print "Rekening tabel bijna vol "+Rmax
close (Invoer)
end
end if
end if
end while
Rmax = R - 1
print "Rmax "+Rmax
close (Invoer)
return

print "Tekst"
dim TK\$(Tmax, 4)
Tekst\$ = "Tekst_Kosten.csv"
open (Invoer,Tekst\$)
T = 1
while not eof (Invoer)
Invoer\$ = readline (Invoer)
Veld\$ = explode(Invoer\$, ",")
L = length(Veld\$[0])
TK\$[T,0] = left(Veld\$[0],L-1)
TK\$[T,1] = Veld\$[1]
TK\$[T,2] = Veld\$[2]
T = T + 1
if T > Tmax - 2 then
print "Tekst tabel bijna vol "+Tmax
close (Invoer)
end
end if
end while
Tmax = T - 1
print "Tmax "+Tmax
close (Invoer)
return

BijzoekenKostenplaats: #
print "Zoeken"
Invoer = 1
Invoer\$ = "ASNS.dta"
open (Invoer, Invoer\$)
Uitvoer = 2
Uitvoer\$ = "ASNSK.csv"
if exists (Uitvoer\$) then kill (Uitvoer\$)
open (Uitvoer, Uitvoer\$)

In = 0
Uit = 0
while not eof (Invoer)
InData\$ = readline (Invoer)
Kosten\$ = "?"
Reden\$ = ""
In = In + 1
Veld\$ = explode (InData\$, ",")
Credit\$ = Veld\$[1]
gosub ZoekCredit
if Kosten\$ = "?" then gosub ZoekTekst
UitData\$ = left(InData\$, length(InData\$)-1) +","+ left(Kosten\$, length(Kosten\$)) +","+ Reden\$
writeline (Uitvoer, UitData\$)
Uit = Uit + 1
Kosten\$ = ""
Reden\$ = ""
end while

close (Invoer)
close (Uitvoer)
print "In "+In+" Uit "+Uit
print "vervolg met RapKost"
return

ZoekCredit: #
For R = 1 to Rmax
if RK\$[R,1] = Veld\$[2] then
Kosten\$ = RK\$[R,2]
return
end if
next R
return

ZoekTekst: #
Veld\$[6] = lower(Veld\$[6]) # omdat TK\$ lower is
For T = 1 to Tmax
Plaats = instr(Veld\$[6],TK\$[T,0])
if Plaats > 0 then
Reden\$ = TK\$[T,0]
Kosten\$ = TK\$[T,1]
return
end if
next T
return