I get "Access forbidden". All I can find about this is "The requested access to the file is not allowed, or search permission is denied for one of the directories in the path prefix of pathname, or the file does not exist yet and write access to the parent directory is not allowed."

As access rights to the program's folder are OK (and I understand the file would be created there). So I guess I can't simply use a string variable as a file name?

If I read your request correctly there is a very easy way to do this in Gambas. The reason you are getting "Access forbidden" is because you are trying to write your file to the root directory which you are not allowed to do. Your 'Home' directory is the place to save your file and Gambas can point to that with 'User.Home'. Have a look at the code below, if you run it you will find that a new file "MyFile.txt" has been created in your Home folder. Also notice the '&/' which will sort out the necessary '/' needed in the path. (It can also remvove too many '/' if required.)

If I read your request correctly there is a very easy way to do this in Gambas. The reason you are getting "Access forbidden" is because you are trying to write your file to the root directory which you are not allowed to do. Your 'Home' directory is the place to save your file and Gambas can point to that with 'User.Home'. Have a look at the code below, if you run it you will find that a new file "MyFile.txt" has been created in your Home folder. Also notice the '&/' which will sort out the necessary '/' needed in the path. (It can also remvove too many '/' if required.)

(...)

If you post the original RealBasic code we may be able to help you further.

Thanks. Why does Gambas default to the root directory? I never thought of that. But OK, now I managed to write to a subdirectory of home, so I can put my files somwhere and keep home tidy

>If you post the original RealBasic code we may be able to help you further.

I'll probably *have* to do that while my work progresses. I'm at the start and I try to get the basic stuff to run (which should not be too difficult I hope). WHen I get to the more complicated things I'll probably be back

If you were running a Distro like Puppy that gives you access to all the directories without the need to use 'sudo' or root passwords Gambas will happily put your new file in the 'root' directory. This is fine but allows you to really screw things up very easily if you don't know what you are doing, or make a genuine mistake.

I suspect you are using Ubuntu, Mint, Fedora, SUSE or similar that protects the 'root' files from accidental mishaps by requiring the need to use 'sudo' or a root password. This can be done in Gambas but to protect your system requires a little more work.

I see you are not using a GUI program, that is where Gambas has some real strengths. Have a look at the Gambas Farm. You will find example programs that may help you, some written by me and hopefully some by you in the near future.

Thanks for joining the site and we look forward to hearing from you soon.