Posted: 14th Jun 2007 16:44
i am trying to open a fle, write two memblocks one after another to it and close. When I use open to write and call write memblock I get an error saying the file is not open. Clearly it should be as i ust opened it. There must be something stupid i'm missing.

Here is my code [you'll need to omit the image bit or load an image up]

+ Code Snippet
save_level:

filedata(0)=p1posx
filedata(1)=p1posy
filedata(2)=p2posx
filedata(3)=p2posy


make memblock from image 1,1
make memblock from array 2,filedata()
open to write 1,"test"
`next line is saying file not open to write????
write memblock 1,1
write memblock 1,2
close file 1
cls
print " Level file created (hit return key to exit)"
wait key
end

Posted: 14th Jun 2007 17:04
Did you try checking if the file exists and deleting it? as Open To Write will create a file, but the file must not exist for it to work.
Posted: 14th Jun 2007 17:49
i could but i'm looking at the folder with hidden file showing and there is no temp there so i doubt thats the problem.

The error says the file is not open
Posted: 14th Jun 2007 22:52
this is really strange beginning to think it's a bug of some sort. Can anyone test it out for me???

(btw have restarted the pc 3 times already)
Posted: 14th Jun 2007 23:21
Before you open the file, check to see if it exists. If it does, delete it. Then you can open the file.

+ Code Snippet
if file exist("test") then delete file "test"
Posted: 15th Jun 2007 2:29
I have discovered my problem it was because the paths are not relative. I solved it by calling kernel32.dll and finding the application path then cutting off the application name. There seems to be no commands in db to find app path they all return either my documents or windows directory.

for anyone interested, found that weird 1234567890 string on the forum dunno why it works but u seem to need it when calling the dll



+ Code Snippet
load dll "kernel32.dll",2
a$="0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789"
enviroment=call dll(2,"GetModuleFileNameA",0,a$,250)
delete dll 2

while right$(a$,1)<>"\"
    a$=left$(a$,len(a$)-1)
endwhile
Posted: 15th Jun 2007 7:03
GET DIR$

This command will get the absolute path of the current working directory. Absolute paths contain the entire path including the drive letter.

Syntax
Return String=GET DIR$()
Posted: 15th Jun 2007 9:34
There seems to be no commands in db to find app path they all return either my documents or windows directory


*cough* APPNAME$() *cough*

... and that weird string is just building a buffer for the API call to put its results into.

This works just as well and is a little easier on the scroll-bar:
+ Code Snippet
load dll "kernel32.dll",2
a$ = space$(250)
enviroment=call dll(2,"GetModuleFileNameA",0,a$,250)
delete dll 2

while right$(a$,1)<>"\"
    a$=left$(a$,len(a$)-1)
endwhile
Posted: 15th Jun 2007 10:57
This works as well obviously

+ Code Snippet
a$=appname$()

while right$(a$,1)<>"\"
    a$=left$(a$,len(a$)-1)
endwhile
Posted: 15th Jun 2007 13:44
lol omg appname$()!!!!! U know I read that command when i was looking through the index but thought it was only going to return the name of the exe so didn't even try it. The help files don't mention that it returns the full path as well.

Anyway thanks guys i can now remove the kernel call.

Was not aware that the DLL needed the string to be sized for it is that always the case?

I haven't been using dll's much but i'm going to have to write a few sprite collision and network commands in the near future. Are there any turorials for writing darkbasic dll's in C#? I can use c++ but not as well.