open files without the user’s help !

I’ve been following chapter 9 of the “IntroductionToProgrammingWithXojo-PDF”.

At the beginning of the chapter, you’ve got the promess that
There are also ways for you to open and save specific files without the user’s help. This will be covered later in this chapter.

But i cannot find where it is taught.

If i am not dreaming, in chapter 9, files are always opened after a user dialog.

Does it lies somewhere else in the book ?

Any replies or small piece of code welcome !

simply create a folderitem object that points to the file, and use TextInputStream or BinaryStream to open it (see LangRef)

Thank you.
But i still don’t know how to put the pathname into the FolderItem…

I’ve got this code for a pushbutton:

Dim myPic As Picture
Dim myFile As FolderItem
myPic = Picture.Open(myFile)
If myPic <> Nil Then
  Canvas1.Backdrop = myPic
  MsgBox("Damn,  not in this folder ")
End If

When i run it,
there is a break and the debugger shows myFile being Nil…

first off a little more research would help… but I understand Folderitems need that “Ah Ha!” moment

dim myFile as FolderItem
myfile=getfolderItem("").child("car007.png")  // this assumes your png in same folder as app
// or perhaps
myfile=specialfolder.desktop.child("car007.png")// assumes it is on your desktop

that should give you enough to go off and find what best fits your requirements…
otherwise comeback with what you have tried, and see what we can do

For sure a little more research would help…

But you know how it is… You want to build more, and less study less!

And i assume what i’ve said. There was a promess in the pdf… And although i am 55, little boys are always unhappy when one breaks promesses !

Your code is what i was looking for anyway.
Thank you Dave.

If you want to make PDF files with Xojo, take a look at my gPDF class… it uses the same syntax as the Xojo Canvas but creates native PDF output

I think he’s just asking where the info that’s missing from the.PDF can be found. I don’t think he wants to create . PDF’s.

Maybe in the accompagnying examples, the project in Chapter 9 ?

List of projects in that folder: Dialogs.xojo_binary_project FileTypes.xojo_binary_project OpenPic.xojo_binary_project Streams.xojo_binary_project StyledTextEditor.xojo_binary_project TextOut.xojo_binary_project TextRead-ListBox.xojo_binary_project TextRead.xojo_binary_project

If you do not have these, re-download the current version from the web site.

Also, a read here: FolderItemDialog.ShowModal

will tell you from where the FolderItem comes: the user select one and place its reference in myFile.

myFile = d.ShowModal

@Emile Schwarz : Thank you for your kind and documented reply.
It was not about dialogs. On the contrary it was about opening a file without using dialogs.

Dim f As FolderItem

f = GetFolderItem(“My_File.txt”) // Provided that file exists…

more here:

Sorry, but the book name is: “IntroductionToProgrammingWithXojo-PDF”.

For all the rest, you have to go thru the documentation. In that case, FolderItem, the shared examples. Of course, OpenDialog will open a … dialog. :wink:

It is indeed unfortunate that the intro guide promises to cover how to get a folderitem without using a dialog, but never actually does. It uses GetFolderItem and SpecialFolder in chapter 12, without any explanation though. So you will eventually see an example, but you won’t be told much about how to use them.

I was not specific enough about the above sentence.

Introduction is just introduction, not exhaustive presentation. To get a more complete (but not total information), reading the language reference is the way to go.

That is a lesson I learnt more than 30 years ago with AppleSoft BASIC.
(AppleSoft BASIC. booklet versus Language Reference two books)

Edit: Complement.
The introduction book allow the reader to learn what to do with FolderItem / FolderItem instruction is to deal with File(s)/Folder(s).

I understand the question(s), but the name of the part is: 9.4 Handling Open/Save Dialogs (Chapter 9: In & Out).
Once more: I understand the question, but Gilles forgot to make his home work.

I think FolderItem is one of the more obscure / hard to wrap your head around classes in Xojo. Once you understand it, it makes perfect sense, but until then it is rather confusing. I think the intro guide could do a better job on it. At least complete the chapter and introduce GetFolderItem, SpecialFolder and FolderItem.Child. It would go a long way toward helping beginners use something as fundamental as the file system.

On page 144 it says

[quote](There are also ways for you to open and save specific files
without the user’s help. This will be covered later in this chapter.)
Either take that out or finish the chapter. My vote would be finish the chapter. @Paul Lefebvre , you need any help on it? I’d be willing to contribute some text.

@Tim Hare,
Thank you for understanding perfectly my point of view.

As i meant, i am quite old and thought about going back into programming after a long long time and the technology having so so much evolved.

I thought it could be fun, and after a while and some searches made, i stopped and selected Xojo as a tool which can be simple and complete enough to permit me to close some of the gap ( 1995 - 2018 ! ).

I try to have fun, and it is long and difficult to obtain what you need from the documentation(s).

Today, i went through
and i swear i didn’t found what i was looking for…

I need to open a file which lays in a child folder relative to the one of the app ( say the working folder )
( My working folder is located at say “WorkinFold” and i need to open files at “WorkinFold/images” )

I cannot find it out !

Am i under a damnation ?

[quote]dim f as folderitem
f = getfolderitem(“images/somefile.txt”)[/quote]
This only works in a compiled app. When debugging, the paths are different.
For this and other reasons, dont assume a file is local to your app, have the file in specialfolder.applicationdata

This only works in a compiled app.
Thank you.
have the file in specialfolder.applicationdata
I will read this. OK.

BTW, please, how can you quote someone/smtgh ?

Use the double quote image at the top right corner of the message that you want to quote.