Search notes:

Testing dbgFileWriter

dbgFileWriterTest.bas

option explicit

global dbg_ as new dbg

sub main() ' {

    dim fileWriter as new dbgFileWriter
    fileWriter.init(environ("TEMP") & "\dbgFileWriterTest.txt")

    call dbg_.init(fileWriter)

    dbg_.text("dbg_ is initialized")

    dbg_.text("func_one returned " & func_one(42))


end sub ' }

function func_one(num as long) as long ' {
    dbg_.indent("func_one, num = " & num)

    if num > 40 then
       dbg_.text("num > 40, call func_two")
       func_one = func_two(num-6)
    elseif num > 20 then
       dbg_.text("num > 20, call func_one")
       func_one = func_three(num-12)
    else
       dbg_.text("add 5")
       func_one = num + 5
    end if

    dbg_.text("returning " & func_one)

    dbg_.dedent

end function ' }

function func_two(num as long) as long ' {
    dbg_.indent("func_two, num = " & num)

    if num > 20 then
       dbg_.text("num > 20, call func_three")
       func_two = func_three(num-14)
    elseif num > 10 then
       dbg_.text("num > 10, call func_one")
       func_two = func_one(num+7)
    else
       dbg_.text("adding 6")
       func_two = num + 6
    end if

    dbg_.text("returning " & func_two)

    dbg_.dedent

end function ' }

function func_three(num as long) as long ' {
    dbg_.indent("func_three, num = " & num)

    if num > 40 then
       dbg_.text("num > 40, call func_two")
       func_three = func_two(num-8)
    elseif num > 20 then
       dbg_.text("num > 20, call func_three")
       func_three = func_one(num+3)
    else
       dbg_.text("add 4")
       func_three= num + 4
    end if

    dbg_.text("returning " & func_three)

    dbg_.dedent

end function ' }
Github repository VBAModules, path: /dbg/tests/dbgFileWriterTest.bas

Output

When invoking the main function from the test module, it will write something like the following into the output file:
2019-01-21 08:41:14 dbg_ is initialized
2019-01-21 08:41:14 { func_one, num = 42
2019-01-21 08:41:14   num > 40, call func_two
2019-01-21 08:41:14   { func_two, num = 36
2019-01-21 08:41:14     num > 20, call func_three
2019-01-21 08:41:14     { func_three, num = 22
2019-01-21 08:41:14       num > 20, call func_three
2019-01-21 08:41:14       { func_one, num = 25
2019-01-21 08:41:14         num > 20, call func_one
2019-01-21 08:41:14         { func_three, num = 13
2019-01-21 08:41:14           add 4
2019-01-21 08:41:14           returning 17
2019-01-21 08:41:14         }
2019-01-21 08:41:14         returning 17
2019-01-21 08:41:14       }
2019-01-21 08:41:14       returning 17
2019-01-21 08:41:14     }
2019-01-21 08:41:14     returning 17
2019-01-21 08:41:14   }
2019-01-21 08:41:14   returning 17
2019-01-21 08:41:14 }
2019-01-21 08:41:14 func_one returned 17

See also

dbg tests

Index