im trying to...

Blitz3D Forums/Blitz3D Beginners Area/im trying to...

Well I'm trying to do this:
if newfile is clicked (value 1)
then if filein doesnt exist create temp.dat
else
delete temp.dat
and create temp.dat
closefile

How should I do it?
this shouldnt be to hard im guessing


  If newfile = 1 Then
	  
	  If Not ReadFile (filein) = 0 Then
	      filein = WriteFile("temp.dat")
	     CloseFile( filein )
	    newfile = 0
	  EndIf
	
	
	EndIf


easy :)
if newfile=1
    if filetype("temp.dat")=0 ;-----if file doesnt exits
       filein=writefile("temp.dat") ;create the file
       closefile(filein)
    else ;--------------------------else
       deletefile("temp.dat") ;-----delete the file
       filein=writefile("temp.dat") ;create the file
       closefile(filein)
    endif
endif


Hmmm, think your description will only work if filein$ = "temp.dat", or at least either both or none of them should exist. what exacly do you want to do? Got four options, depending on wich of the two files exist.

Ford, your quotation marks are a little on the screwy side :)

yeah let me try again without the screwy quotations ^-^ and with a more generic function :)

if newfile=1
   makefile("","temp.dat")
endif
;
;
;
;
function makefile(directory$,filename$)
   if filetype(directory$+filename$)=0         
      filein=writefile(directory$+filename$) 
      closefile(filein)
   else
       deletefile(directory$+filename$)   
       filein=writefile(directory$+filename$) 
       closefile(filein)
    endif
end function


fonction can only appear in the main program?
what does that mean?

....

Global newfile = 0

Repeat

.....

	; NEW FILE
	If newfile=1
   makefile("","temp.dat")
     newfile=0
EndIf


;-----------------------
; FONCTIONS
;-----------------------


Function makefile(directory$,filename$)
   If FileType(directory$+filename$)=0         
      filein=WriteFile(directory$+filename$) 
      CloseFile(filein)
   Else
       DeleteFile(directory$+filename$)   
       filein=WriteFile(directory$+filename$) 
       CloseFile(filein)
    EndIf
End Function



Forever
End


not in the loop... riiiighhht