New topic: Open a database file using a file selector
<http://forums.realsoftware.com/viewtopic.php?t=47790> Page 1 of 1 [ 4 posts ] Previous topic | Next topic Author Message WonkeyDonkey999 Post subject: Open a database file using a file selectorPosted: Sat May 04, 2013 6:25 pm Joined: Thu May 10, 2007 3:23 pm Posts: 8 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 timhare Post subject: Re: Open a database file using a file selectorPosted: Sat May 04, 2013 11:59 pm Joined: Fri Jan 06, 2006 3:21 pm Posts: 12295 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 WonkeyDonkey999 Post subject: Re: Open a database file using a file selectorPosted: Sun May 05, 2013 7:07 am Joined: Thu May 10, 2007 3:23 pm Posts: 8 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 harriew Post subject: Re: Open a database file using a file selectorPosted: Sun May 05, 2013 9:14 am Joined: Fri Dec 01, 2006 3:09 pm Posts: 648 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 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 4 posts ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
