in subroutinen und funktionen benutzt man auch kein
dim, sondern local

also an stelle von :
dim digit0 as byte

dann
local digit0 as byte