  Rank: Advanced Member Groups: Registered
Joined: 04/07/2010(UTC) Posts: 178   Was thanked: 19 time(s) in 13 post(s)
|
How can I get the current SMath file name using VB Express?
I have a plugin that when a particular function is called the user is presented with the normal open file dialog box. What I want though is if the page is ever recalculated that function will not execute(unless deliberately requested). The file name is retained and prevents the function from re-executing.
The only way I can think of to retain the file name values between sessions is to store them somewhere. And the only place I've come up with is a shadow file INI that has the variable name and value. If the SMath file is called C:\...\MyFile.sm a INI file C:\...\MyFile.ini will exist.
The first time the function is defined the open file dialog box will appear and the user can select the file. The plugin will store that value.
The INI file will have a record like this fn1=C:\...\SomeDataFile.dat fn2=C:\...\SomeMoreData.dat
In SMath
fn1:=getFile(fn1)
If fn1 has a value in INI file set fn1 to that value If fn1 not otherwise defined the open file dialog box appears. To deliberately open the dialog box do this.
fn1:=0 fn1:=getFile(fn1)
Then delete the fn1:=0 line.
The getFile() function will work with a getData() function
fn1:=getFile(fn1) data:=getData(fn1,"key" ) where the fn1 file is search for the "key" and returns the value(s).
Any suggestions, concerns are welcome
PS Which leads me to another question. Any suggestions on plugin function naming to avoid conflicts?
|
Ed |
|
|
|
  Rank: Administration Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member Joined: 11/07/2008(UTC) Posts: 1,639   Was thanked: 2011 time(s) in 679 post(s)
|
I cannot imagine the way how to get current file name. And even if it will be possible, then what to do with a file if it was not saved before?
Here is my thoughts about how to realize the logic you talking about: 1) getFile function should contains a string argument, that will mean some unique identifier of the file - its UID. 2) first time getFile function called Open File Dialog will be shown and the chosen file name will be saved in a file with name that equals to UID from the argument and its content will be the full path to the chosen file. Location of this file will be in some special directory you plugin knows about. 3) any second time getFile function called plugin will check if the special directory contains a file with specified by function's argument name, then the file name of the data file will be read from that file. If not, then go to step 2).
This has an interesting side effect - you can use the same UIDs for getFile functions from the different SMath files.
Regards.
|
|
|
|
  Rank: Advanced Member Groups: Registered
Joined: 04/07/2010(UTC) Posts: 178   Was thanked: 19 time(s) in 13 post(s)
|
I was hoping in the Dispose method I could save a shadow file in the same directory and with the same name but with ini extension. Thats where I write the Ini file from memory. Here's what I have so far.  This process will work with the fn=wgetFile(fn) function I'm working on. Where fn will equate to some file in the Ini file. Notice you have to equate the plugin function to something for the function to execute. Now I just need to get the plugin path name to store the shared file. |
Ed |
|
|
|
  Rank: Administration Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member Joined: 11/07/2008(UTC) Posts: 1,639   Was thanked: 2011 time(s) in 679 post(s)
|
Path to the plugin folder: Code:GlobalParams.ApplicationPath + "plugins" + Path.DirectorySeparatorChar
|
|
|
|
  Rank: Advanced Member Groups: Registered
Joined: 04/07/2010(UTC) Posts: 178   Was thanked: 19 time(s) in 13 post(s)
|
Andrey,
Windows 7 doesn't let the user write to the plugin directory from the application.
I'll have to figure out another strategy for the the shared Ini file.
Thanks for your help. I'm close to finishing. But programming is a hobby, I still have my day job. |
Ed |
|
|
|
  Rank: Administration Groups: Developers, Registered, Knovel Developers, Administrators, Advanced Member Joined: 11/07/2008(UTC) Posts: 1,639   Was thanked: 2011 time(s) in 679 post(s)
|
TheWizEd wrote:Windows 7 doesn't let the user write to the plugin directory from the application. Yeah, Windows Vista as well. This is a reason of why we also have field GlobalParams.SettingsDirectory - it returns "C:\Users\[User Name]\AppData\Roaming\SMath\" and it works for both Desktop and Handheld versions. Regards.
|
|
|
|
  Rank: Advanced Member Groups: Registered
Joined: 04/07/2010(UTC) Posts: 178   Was thanked: 19 time(s) in 13 post(s)
|
Andrey, Works fine now. I have been testing only with text values. I need to test with numeric data in the ini file. All sheets that use any of these Ini keys will be changed. That can be good or bad. That was why I would have liked it to be associated with the date file. By the way I use the Dispose method to write the Ini values if they are dirty. First SMath session:  When exiting SMath if the Ini values are changed "dirty" the user is asked whether or not they want to save the Ini values. Just in case they made a mistake.  Second SMath session:  Third SMath session:  I think I need to come up with a better naming convention. Too much typing |
Ed |
|
|
|
  Rank: Advanced Member Groups: Registered
Joined: 04/07/2010(UTC) Posts: 178   Was thanked: 19 time(s) in 13 post(s)
|
Andrey, I'm have a slight problem with numeric values. Decision seems to convert floating point numbers to a lowest denominator form. I had planned on testing IsNumeric to see if it was a number or a string. But that idea won't work now.  Any suggestions on testing the argument? |
Ed |
|
|
|
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.