Need to store variables on secondary storage at run time

Started by sunnyimran, March 07, 2019, 05:14:26 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

sunnyimran

Hi there,

Great forum, I got helped here a lot for my specific Visio tasks

I have dome some VBA scripting in Visio 2016. The script has certain variables, user selected parameters and script generated data like random numbers, file names etc. Most of them changes on each iteration. Process iterates for a large number of times as user selected. Sometimes for more than a thousand iteration on user selected. Whole iterations may take three to four hours to complete.

Working fine. I want to have additional facility:

I want flush (store) crucial data as variable values, user selections, script generated data right at a moment, store on secondary storage HDD or wherver.

This will help me to close and restart the script from the place from where it was stopped.

Currently there is no option to pause or stop script in the middle otherwise script have to start over again.

Other reason compelling me to do it for example are if Systems hangs for a hardware fault, glitch in electric power, blackout, brownout etc. etc. ...

Please give me some hints/pointers how can I write my crucial data on HDD etc. on the fly. at specific intervals, say after completing one loop or at any other event.

Waiting.

Paul Herber

Have you considered writing some data to the registry?
Electronic and Electrical engineering, business and software stencils for Visio -

https://www.paulherber.co.uk/

vojo

I assume you are aware that VBA has saveas  dialogues for this kind of thing.
So in the middle of a given script, could jump to a function that saves the info then return back to script to continue

simple example

Public Sub SaveAs_Example() 
 
    'Use the SaveAs method to save a document for the first time. 
    ThisDocument.SaveAs "path\filename .vsd"
 
End Sub

sunnyimran

Yea I am aware of that,
I am not concerned with saving whole document time to time. That also my script doing on each iteration.

Things I wanted to store does not belong to whole Visio doc, template or stencil. Things are like variables, dictionary object, strings etc. that I am interested to flush to HDD frequently.

Any ideas for that?

Yacine

You're looking for something like an ORM - object relational mapper.
https://www.google.de/search?newwindow=1&safe=off&ei=uneCXKPiOYqxrgS0s6zwBg&q=orm&oq=orm&gs_l=psy-ab.3..0i20i263l2j0l3j0i7i30l2j0l2j0i67.348405.348405..348798...0.0..0.93.93.1......0....1..gws-wiz.......0i71.pknY2FrUJDs

Some ideas:
1) write one sub in which you collect all the variables, then save (to file, access or excel)
  myList = [var_a, x, y, var_b]
  save...
 
  caveat you need to maintain this list
2) use a function with key, value pairs for your variables
  v_set "forename", new_value
  ....
  result = v_get("some other variable")
  here also you would save the table. You just avoid collecting the values. The variables write their values by themselves when used.
Yacine

vojo

np

I had lots of challenges with Savesas since there are something like 8 parameters you can tailor (file format, append or overwrite, etc).

Basically, that was the tough nut to crack for doing this kind of thing (at least in an Excel tool I did for day job).
Be advised, if other users will use your scripts, probably want to consider security setting checks for new users.

sunnyimran

ORM - object relational mapper.
I googled, not deeper but initial thought seems it will make the script more complex.

Using INI for not-so-frequent data
I have created a User form for relatively static info. File Open dialog to connect to user's chosen MS Access database. At form initialize, it reads value from a previously saved INI file into a Dictionary. Then from "Scripting.Dictionary" values, the text boxes in user form are populated. If user made any selection changes here than they are updated in the "Scripting.Dictionary" and finally when user clicks to go to next Form, INI file is updated with "Scripting.Dictionary". Quite convenient. I chose "Scripting.Dictionary" because it very closely resembles the INI rules. key and value pairs.

Above all is good for saving parameters which are retrieved/updated once at each program run. Challenge is for updating values which are constantly changing during each iteration.

To give it a start I have similar idea link INI that will fulfill the need up to some extent. I will create another dictionary, populate it with data to be saved on HDD. Before main iterations start I will open INI file for Read/write using System file Object. During each iteration, I will keep updating this "Scripting.Dictionary" and after each iteration completes and before looping back I will update the Dictionary to INI file overwriting previous ones.  Making an auto backup after some iterations will also good idea.

That's the idea in my mind at the moment. Only problem is that it will not be helpful in cases of hardware/system hangs or power cuts. But even though I can edit INI manually out of visio and at least will get values of a step or two back iterations.

Have anyone used MS-OneNote, the note taking application from MS?
Good thing about it is there is no "save" hassle. whatever you write gets immediately (or very frequently) written to permanent storage where your Note book is stored. a Cache on HDD is also involved. But that of course is a deeper level of programming.

I don't think VBA can offer a way like this, is it?
Or can we find a way to keep our such variable data in a specific range of RAM and at system level that range of RAM may be written to secondary storage frequently. That will take me out of opening and closing files.

so please comment what do you think