Open files in program

BlitzPlus Forums/BlitzPlus Programming/Open files in program

Hmmm. I have no idea how to do this:
Make it that when you double click on the icon for your file type (which works exclusively to your program), that it then opens your program (done that bit so far) and then reads that file, and sets up the file accordingly, rather than opening a new file in the program.
Anyone?

Use CommandLine().
The file you double-clicked on will be the first parameter.

Thanks!
It works when i put the filename as the command line, but doesnt when i open a file: It states 'Invalid Stream Handle'
I'll give it a good look over to see what i've done wrong
(probably variables mixed/localised or something hastily stupid like that...)

Edit: hmm. couldnt find the problem.
Alright, Heres my code (sampled):
Global loadingfirst$=CommandLine$()
Type tile
	Field ver
	Field x
	Field y
End Type
Global b.tile

Global tilesetimage,tilefilename$="",nTilevers,xtiles,ytiles,MouseTile=-1,utiles=75,vtiles=75,mx,my,mapfilename$="",ReplacedMouseTile

If Not Asc(loadingfirst$)=0
	OpenTileMap(1)
EndIf

Function OpenTileMap(beginfile=0)

	If beginfile=0;check if command lien is enabled!"
		choice=Confirm("Are you sure you want to open?")
		If choice=0 Then Return False
		choice=0
	
		oldmapfilename$=mapfilename$
		mapfilename$=""
	
		mapfilename$=RequestFile("Open a Map","zmap,zfront")
		If mapfilename$="" Then mapfilename$=oldmapfilename$ Return False
	Else
		mapfilename$=loadingfirst$
	EndIf
	
	;remove current memory status(if opening in menu)
	For b.tile=Each tile
		Delete b.tile	 
	Next
		
	Print mapfilename$;-always comes up with the correct file...?
	;open the file to read
	file=ReadFile(mapfilename$)
	If file=0 Then RuntimeError("file handle failed: "+mapfilename$);keeps happening...?
	utiles=ReadByte(file)
	vtiles=ReadByte(file)

	For u=0 To (utiles-1)
	For v=0 To (vtiles-1)
		b.tile=New tile
		b\ver=ReadShort(file)-1
		b\x=16*u
		b\y=16*v
	Next
	Next
	CloseFile file	
End Function



Like i have said, it works within Blitz, but once compiled, fails to work......Help

Problem solved. Insert this line before you try to open the file:
mapfilename=Trim(Replace(mapfilename, Chr$(34), " "))

Readfile doesn't like the quotes -- it was as if you were calling Readfile(""file"") and it didn't like that.

Thanks again!!
Ill be using that piece of code in everything i read!