PDA

View Full Version : Problem with get file



ana027
10-25-2007, 10:20 AM
Hi all, I'm testing this little script and the script is too easy but I don't know how can I make.

The script has one filename and a button to get the filename. When you set the file to write with the filename button after you can push the write button and the script must write the file with the path but the script don't make.

Anyone can tell me which is the error ?



@version 2.3

options
{
file = "default";

reqbegin("My Requester");
reqsize(500,170);

c1 = ctlbutton("Write",80,"button_callback_c1");
ctlposition(c1,141,76);

c2 = ctlfilename("Filename",file);
ctlposition(c2,139,49);

return if !reqpost();

file = getvalue(c2);

reqend();
}

button_callback_c1
{
// perform processing here

if(file == nil)
return nil;

basefile = split(file);
filename = string(basefile[1],basefile[2],basefile[3],".dat");

file = File(filename,"w");
if(file == nil)
{
error("Cannot Create File");
return nil;
}

file.writeln("@warnings");
file.writeln("@version2.3");
file.close();

info("Write");

reqend();

}

LightFreeze
10-26-2007, 06:17 PM
without trying it it looks like you are jumping to the callback before you have read the filename, then you close the requestor,so file always = "default", try putting

file = getvalue(c2);

inside the callback but you will need to make c2 global

ana027
10-27-2007, 01:43 AM
Can I used too ctlrefresh ?

ana027
10-27-2007, 02:26 AM
Yes, I try ctlrefresh and works fine :)