Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 20, 2017 6:12 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Open a database file using a file selector
PostPosted: Sat May 04, 2013 6:25 pm 
Offline

Joined: Thu May 10, 2007 3:23 pm
Posts: 9
I just wanted to do a quick check to make sure Im doing things right. It seems to work ok here.

I'm writing a small database program. The user clicks to open up a file selector and can then select a database file to open from that location, or navigate elsewhere to select a file.

The code I have is :

Dim f as FolderItem
Dim db as new REALSQLDatabase

f = GetOpenFolderItem("" ) ' Display file selection dialog to allow user to choose a file
db.databaseFile = getFolderItem(f.AbsolutePath) ' Set the target database filename using the full path, instead of a relative path

MsgBox "The database filename is :" +f.Displayname ' Quickly show me the name of the file
MsgBox "The location of this file is :" +f.AbsolutePath ' Show me the full path of the file

If db.Connect then ' Try to open the file
' Code here to check we can open the file ok. No need to check if the file exists since the user has just selected it.


Is the code above ok for this task or is there a better way to do it ?

Thanks.


Top
 Profile  
Reply with quote  
 Post subject: Re: Open a database file using a file selector
PostPosted: Sat May 04, 2013 11:59 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
That's a good approach. The only comment I have is

db.databaseFile = getFolderItem(f.AbsolutePath) ' Set the target database filename using the full path, instead of a relative path

can be simply

db.databaseFile = f


Top
 Profile  
Reply with quote  
 Post subject: Re: Open a database file using a file selector
PostPosted: Sun May 05, 2013 7:07 am 
Offline

Joined: Thu May 10, 2007 3:23 pm
Posts: 9
Ahh ok.

So what we are really saying here then is that f on its own contains the filename only following the GetOpenFolderItem, but f.propertyname is also generated containing various other values because of the intial FolderItem.

If that follows, then f is actually the same as f.DisplayName.

Is that the right thinking ?


Top
 Profile  
Reply with quote  
 Post subject: Re: Open a database file using a file selector
PostPosted: Sun May 05, 2013 9:14 am 
Offline

Joined: Fri Dec 01, 2006 3:09 pm
Posts: 650
Location: Tennessee, USA
You need to better understand the properties that you are working with. In your code f is a folderitem and db is a RealSqlDatabase class.
f=GetOpenFolderItem(" ")
returns a folderitem so long as the user did not click the cancel button in the dialog window. If you look up the REALSQLDatabase class in the LR you will see that the dabaseFile property is a folderitem and so
db.databaseFile = f
is assigning that folderitem to the databasefile property of db. db now has the name, the path, and all of the other properties of a folderitem, not just the name. You are in essence assigning the location of the database file, not just the name.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group