Get current file name

Get current file name - Сообщения

#1 Опубликовано: 15.08.2010 13:47:58
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

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
#2 Опубликовано: 15.08.2010 16:10:29
Andrey Ivashov

Andrey Ivashov

2270 сообщений из 3734 понравились пользователям.

Группа: Super Administrator

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.
#3 Опубликовано: 21.08.2010 23:38:09
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

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
#4 Опубликовано: 22.08.2010 07:15:03
Andrey Ivashov

Andrey Ivashov

2270 сообщений из 3734 понравились пользователям.

Группа: Super Administrator

Path to the plugin folder:
GlobalParams.ApplicationPath + "plugins" + Path.DirectorySeparatorChar
#5 Опубликовано: 22.08.2010 09:52:08
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

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
#6 Опубликовано: 22.08.2010 16:58:39
Andrey Ivashov

Andrey Ivashov

2270 сообщений из 3734 понравились пользователям.

Группа: Super Administrator

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.
#7 Опубликовано: 22.08.2010 18:11:01
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

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
#8 Опубликовано: 28.08.2010 12:09:29
Edward Ulle

Edward Ulle

20 сообщений из 182 понравились пользователям.

Группа: Moderator

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
  • Новые сообщения Новые сообщения
  • Нет новых сообщений Нет новых сообщений