Hi,
I have the "LogSave" procedure for saving logs into the "Log.txt" file. I did open the file and write string. But my file is empty.
Please help and tell me where is my mistake.
Files "code_0001.dba" & "code_0002.dba" in one Project.
file "code_0001.dba"
` ------ Declare variables
` --- Core
global dim CoreInt(1000) as integer
global dim CoreFlo(1000) as float
global dim CoreStr(1000) as string
global dim CoreOpt(100) as string ` Array for load engine options
` --- Log
global LogIndex = 0
global LogStrings = 255
global LogState = 0
global dim LogTemplates(1000) as string ` Language file (eng or rus)
global dim LogStrings(LogStrings) as string ` Array for Log system
global Process as string ` Current process
global TempProcess as string ` Var for save current process
` --- File Handles
local FileSystemPref = 1
local FileLog = 2
` --- File Names
local FileNameSystemPref$ = "system.pref"
local FileNameLog$ = "log.txt"
` --- Pick String
global PickString$
` --- Start program
Result = LogSetup(FileLog, FileNameLog$)
LogSave("Root process", "Start core", LogState)
Result = PrefSetup(FileSystemPref, FileNameSystemPref$)
`------------ Check load error
if Result = 1
print "exit"
print "press any key"
wait key
end
endif
`------------ End check
Result = CheckVersion()
Result = LogSave(Process, "Version: " + PickString$, LogState)
print "Var out: " ; str$(Result)
` --- Stop
close file FileLog
wait key
end
` --- Screen
global ScrW as integer ` Width of Screen
global ScrH as integer ` Height of Screen
global ScrD as integer ` Depth of Screen
remstart
--------
0*x*** - Root
1*x*** - Subprogram
2*x*** - Procedures
------
00x0a1 - Initializing system
20x0a2 - Setup system preferences
20x0a3 - Check verion
------
remend
file "code_0002.dba"
` ------ Functions file ------ `
` --- System Preference
function PrefSetup(FileSystemPref, FileNameSystemPref$)
TempProcess = Process
Process = "20x0a2"
`--------------------
if file exist(FileNameSystemPref$) = 1
print "file system.pref opened ok"
load array "system.pref", CoreOpt()
else
print "error: file system.pref not found"
exitfunction 1
endif
`--------------------
Process = TempProcess
endfunction 0
function CheckVersion()
TempProcess = Process
Process = "20x0a3"
`--------------------
CheckString$ = CoreOpt(0)
PickStringCondition$ = " "
PickString(CheckString$, PickStringCondition$, 1)
print "Engine ver." ; val(PickString$)
`--------------------
Process = TempProcess
endfunction 0
function PickString(CheckString$, PickStringCondition$, PickStringCounter)
TempProcess = Process
Process = "20x0a4"
`--------------------
LenStr = len(CheckString$)
` --- Check length for zero
if LenStr = 0
exitfunction 1
endif
PickString$ = ""
` --- Find argument PickStringCounter = 0
if PickStringCounter = 0
c = 1
do
PickStringLetter$ = mid$(CheckString$, c)
` --- Check comment
if PickStringLetter$ = ";"
exitfunction 3
endif
` --- Check condition symbol
if PickStringLetter$ = PickStringCondition$
exitfunction 0
endif
PickString$ = PickString$ + PickStringLetter$
inc c
` --- Check out of string
if c > LenStr
exitfunction 2
endif
loop
endif
` --- Find argument PickStringCounter > 0
if PickStringCounter > 0
c = 1 ` for pick letter
d = 0 ` for count conditions
do
PickStringLetter$ = mid$(CheckString$, c)
` --- Check comment
if PickStringLetter$ = ";"
exitfunction 3
endif
` --- Check condition symbol
if PickStringLetter$ = PickStringCondition$
inc c
inc d
` --- Check number condition word
if d = PickStringCounter
do
PickStringLetter$ = mid$(CheckString$, c)
` --- Check condition symbol
if PickStringLetter$ = PickStringCondition$
exitfunction 0
endif
PickString$ = PickString$ + PickStringLetter$
inc c
` --- Check end of string
if c = LenStr
PickStringLetter$ = mid$(CheckString$, c)
PickString$ = PickString$ + PickStringLetter$
exitfunction 0
endif
loop
endif
inc c
` --- Check out of string
if c > LenStr
exitfunction 2
endif
endif
inc c
` --- Check out of string
if c > LenStr
exitfunction 2
endif
loop
endif
`--------------------
Process = TempProcess
` --- Error codes
` 1 - Empty string
` 2 - String not found
` 3 - Source string is a comment
endfunction 0
` --- Save Log
function LogSave(LogProcess$, LogString$, LogState)
`-----------------
local a as integer
`--- Save dim and file 1 string
if LogState = 0
LogString$ = get date$()+" "+get time$()+ " "+LogProcess$+" "+LogString$
LogStrings(LogIndex) = LogString$
inc LogIndex
write string LogFile, LogString$
LogIndex = LogIndex and LogAllStrings ` any number will and 255
exitfunction 0
endif
`--- Save dim. If LogIndex = 255 then save all logs into file
if LogState = 1
LogString$ = get date$()+" "+get time$()+" "+LogProcess$+" "+LogString$
LogStrings(LogIndex) = LogString$
inc LogIndex
LogIndex = LogIndex and LogAllStrings ` any number will and 255
if LogIndex = 0
for a = 0 to LogAllStrings
LogString$ = LogStrings(a)
write string LogFile, LogString$
next
endif
exitfunction 1
endif
`--- Save file all current strings
if LogState = 2
for a = 0 to LogIndex
LogString$ = LogStrings(a)
write string LogFile, LogString$
next
exitfunction 2
endif
`-----------------
endfunction 0
function LogSetup(FileLog, FileNameLog$)
`-----------------
if file exist(FileNameLog$) = 1
delete file FileNameLog$
endif
open to write FileLog, FileNameLog$
`-----------------
endfunction 0
` --- Screen Setup
function ScreenSetup()
TempProcess = Process
Process = "20x0a2"
`--------------------
ScrW = desktop width()
ScrH = desktop height()
ScrD = 32
LogSave(Process$, "Screen width: " + str$(ScrW), LogState)
LogSave(Process$, "Screen height: " + str$(ScrH), LogState)
set display mode ScrW, ScrH, ScrD
set window off
sync on
sync rate 0
LogSave(Process$, "Mouse hide...", LogState)
`--------------------
Process = TempProcess
endfunction 0
file "system.pref" (in the root directory of project)
Version 1.001
LogLanguage eng
MainConfig main.rcf
ShadersRoot fx
TextureRoot textures
Thanks
sig