const sm = 2 folderin = "/storage/6C9B-A353/SmallBASIC/" 'I suppose this is my home directory since it works for output too. 'folderout = "/storage/6C9B-A353/SmallBASIC/" 'The SD directory I tried to open. But if I now understand correctly, you can't open any other than home directory for output. folderout = "/storage/emulated/0/SmallBASIC/" namein = "testi.bas" nameout = "output.txt" if exist(folderin + namein) then open folderin + namein for input as #1 open folderout + nameout for output as #2 while ! eof(1) linput #1, row row = trim(row) if empty(row) then print #2, row else if instr(1, row, "'") != 1 then if wordplace("if", row) = 1 and wordplace("then", row) in [0, 2] then indent += sm : samerow = -sm end if if wordplace("else", row) = 1 then samerow = -sm if wordplace("elseif", row) = 1 then samerow = -sm if wordplace("end if", row) = 1 then indent -= sm : samerow = 0 if wordplace("endif", row) = 1 then indent -= sm : samerow = 0 if wordplace("select", row) = 1 then indent += sm : samerow = -sm if wordplace("select", row) = 2 then indent -= sm : samerow = 0 if wordplace("case", row) = 1 then samerow = -sm if wordplace("for", row) = 1 then indent += sm : samerow = -sm if wordplace("next", row) = 1 then indent -= sm : samerow = 0 if wordplace("repeat", row) = 1 then indent += sm : samerow = -sm if wordplace("until", row) = 1 then indent -= sm : samerow = 0 if wordplace("while", row) = 1 then indent += sm : samerow = -sm if wordplace("wend", row) = 1 then indent -= sm : samerow = 0 end if if samerow + indent < 0 then print "Did not finish!" delay 2000 exit loop end if print #2, space(samerow + indent) + row samerow = 0 end if wend if indent != 0 then print "Indenting went wrong!" delay 2000 end if close #1 close #2 else print "No such file!" delay 2000 end if func wordplace(word, @mj) local p p = instr(1, lcase(mj), lcase(word)) if p != 0 then if p = 1 then if mid(mj, len(word) + 1, 1) = " " or len(mj) = len(word) then return p : exit func end if if p = len(mj) - len(word) + 1 then if mid(mj, p - 1, 1) = " " then return 2 : exit func end if if mid(mj, p + len(word), 1) = " " and mid(mj, p - 1, 1) = " " then return 3 : exit func else return 4 end if return 0 end func