Converting from Lb to Cb.
I did the following example.
FILESAVE$=DDefaultDir$+"\"+"ProjectFiles"+"\" +ProjectName$+"\" +PageName$+".ckl"
def SaveFile:FILE
If (OPENFILE(SaveFile,FILESAVE$,"W")=0)
Write SaveFile, "This is a Test"
CloseFile SaveFile
Any comments of suggestions would be helpful.
Thanks Texas Pete
Try this example:
def SaveFile:FILE
def filename:STRING
filename = "c:\CBTestWrite.txt"
if (OPENFILE(SaveFile,filename,"W")=0)
messagebox 0,"Opened '"+filename+"' for writing.","CB Write Test"
write SaveFile, "This is a Test"
messagebox 0,"Wrote string to '"+filename+"'.","CB Write Test"
closefile SaveFile
messagebox 0,"Closed '"+filename+"'.","CB Write Test"
else
messagebox 0,"Unable to open '"+filename+"' for writing","CB Write Test"
endif
Snarling i think that your example is not right answer.
Pete need first create folder then create subfolder with project name then write file in this subfolder.
How do that - I dont know....?
My example is the basics of what Pete needs to open a file and write to it.
That is exactly what he needs to learn before jumping into converting LB code.
OK your example is base for write file I agree.
But do you see :
DEF FILESAVE$:STRING
DEF filter:STRING
DEF DDefaultDir$, ProjectName$,PageName$:STRING
So my question still stay - how create subfolder in folder ???
Something like this?
def SaveFile:FILE
def filename$,DDefaultDir$,ProjectName$,PageName$:STRING
def handle:INT
DDefaultDir$ = "c:\CBTestDir"
ProjectName$ = "TestProject"
PageName$ = "TestPage"
'Set to path of directory
filename$ = DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$
'Check if DDefaultDir$ exists
handle = findopen(DDefaultDir$)
if (handle == 0)
'If it doesn't exist, create it.
if (createdir(DDefaultDir$) == 0)
messagebox 0,"Error creating '"+DDefaultDir$+"' directory","CB WriteTest"
findclose handle
end
endif
endif
findclose handle
'Check if ProjectFiles exists
handle = findopen(DDefaultDir$+"\"+"ProjectFiles")
if (handle == 0)
'If it doesn't exist, create it.
if (createdir(DDefaultDir$+"\"+"ProjectFiles") == 0)
messagebox 0,"Error creating '"+DDefaultDir$+"\"+"ProjectFiles""' directory","CB WriteTest"
findclose handle
end
endif
endif
findclose handle
'Check if ProjectName$ exists
handle = findopen(DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$)
if (handle == 0)
'If it doesn't exist, create it.
if (createdir(DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$) == 0)
messagebox 0,"Error creating '"+DDefaultDir$+"\"+"ProjectFiles"+"\"+ProjectName$+"' directory","CB WriteTest"
findclose handle
end
endif
endif
findclose handle
'Add file name to the end of the directory
filename$ = filename$+"\"+PageName$+".ckl"
if (OPENFILE(SaveFile,filename$,"W")=0)
messagebox 0,"Opened '"+filename$+"' for writing.","CB Write Test"
write SaveFile, "This is a Test"
messagebox 0,"Wrote string to '"+filename$+"'.","CB Write Test"
closefile SaveFile
messagebox 0,"Closed '"+filename$+"'.","CB Write Test"
else
messagebox 0,"Unable to open '"+filename$+"' for writing","CB Write Test"
endif
Yes... ;D
Oh my I completly forget command FINDOPEN ::)
This is excellent example ,thank you Snarling ;)