我几乎已经完成了将这个文件的内容复制到新文件的结构。
变量numLines
是我遇到的困难。
请参阅第46
行,那里是我遇到的麻烦,第50
行的工作示例以及其他注释。
我尝试使用this.numLines
作为结构体中的那些引用变量。
并且还在fn内部分配了局部变量,但似乎没有任何作用。
(
local readFilePath = @"path to old file here.ms"
local writeFilePath = @"path to new file here.ms"
global _3db_FileOps
local _3db_FileOps_Struct
struct _3db_FileOps_Struct
(
readPath = readFilePath,
writePath = writeFilePath,
rp = dotnetobject "System.IO.Streamreader" readPath,
wp = dotnetobject "System.IO.StreamWriter" writePath,
currLine = 0,
numLines = 0,
fn CloseFiles =
(
try Close readPath catch() ; try Close writePath catch()
),
fn CloseReaders =
(
try rp.Close() catch() ; try wp.Close() catch()
),
fn CountLines =
(
while not this.rp.EndOfStream do
(
this.rp.ReadLine()
numLines += 1
if (mod numLines 500) == 0 do try windows.processPostedMessages() catch()
)
return numLines as integer
close readPath
rp.Close()
),
fn CopyContents =
(
start = timeStamp()
while not this.rp.EndOfStream do
(
arr = this.rp.ReadLine()
this.wp.WriteLine(arr)
--Here I want to progress the progressbar with the equation 100.*currLine/numLines which is not working.
--The numLines variable is not working in this because if I replace that with the blocked
--Not working because of the variable numLines.
-- progressTest.doit_prog.value = 100.*currLine/this.numLines
--This works.
progressTest.doit_prog.value = 100.*currLine/2000
currLine += 1
)
rp.Close()
wp.Close()
end = timeStamp()
format "Processing took % seconds\n" ((end - start) / 1000.0)
)
)
_3db_FileOps = _3db_FileOps_Struct()
)
try destroydialog progressTest catch()
rollout progressTest "Progress Test"
(
button calculate "Scan file"
label fileinfo "Lines in file" style_sunkenedge:true width:180 height:16
button doit "Process file"
progressbar doit_prog color:blue
on calculate pressed do
(
start = timeStamp()
result = _3db_FileOps.CountLines()
_3db_FileOps.CloseFiles()
fileinfo.text = result as string
end = timeStamp()
format "Processing took % milliseconds\n" ((end - start) / 1000.0)
)
on doit pressed do ( _3db_FileOps.CopyContents() ; _3db_FileOps.CloseFiles() )
)
createDialog progressTest 200 120