Real Software Forums
http://forums.realsoftware.com/

Open a database file using a file selector
http://forums.realsoftware.com/viewtopic.php?f=3&t=47790
Page 1 of 1

Author:  WonkeyDonkey999 [ Sat May 04, 2013 6:25 pm ]
Post subject:  Open a database file using a file selector

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.

Author:  timhare [ Sat May 04, 2013 11:59 pm ]
Post subject:  Re: Open a database file using a file selector

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

Author:  WonkeyDonkey999 [ Sun May 05, 2013 7:07 am ]
Post subject:  Re: Open a database file using a file selector

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 ?

Author:  harriew [ Sun May 05, 2013 9:14 am ]
Post subject:  Re: Open a database file using a file selector

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.

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/