Digital Workshop

Welcome to the Digital Workshop Message Boards
It is currently January 8th, 2025, 9:20 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: Writing/Reading Disk File
PostPosted: December 8th, 2009, 4:04 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi,

It's been a while and I can't figure out how to use the write to/read from a single disk file (in <SYSTEM_PUBLICATION_DIR>\) to store multiple variables.

The project would use many different variables based on writing data into many text input boxes (each box would use a different variable to store its input).

Each text input would need to be stored in its own variable in the single text file. Then, this file would need to be read for each variable and the information stored would be displayed in multiple text boxes each with an "insert variable."

I've tried this with "add to existing contents" and "start a new line" then reading from the disk file or reading first line, then next line. Nothing seems to work.

Any help would be appreciated.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject: variables read and write
PostPosted: December 8th, 2009, 6:27 pm 
Offline

Joined: April 5th, 2008, 2:41 pm
Posts: 102
Location: Sydney
Opus: Opus Pro Edition 9.51
OS: Windows 8.1
System: Acer Aspire V touch screen edition 4G RAM
Not 100% SURE I get your meaning - but from what I can figure out - for me anyway, Id do it this way.

Create a variable say you call it [pet]

then create a directory called petdata.

ok create a text input box and the information you typed into this would go to the variable called [pet] - then create a button that has the following actions:

FIRST PART:
On left mouse - save ( variable ) [pets] to c:/petdata.

SECOND PART:
read from diskfile c: petdata - store in variable [pet]
show [pet]


Once this is in memory - hitting the button then firstly ( up-dates ) or "writes" the file to a location be it hard drive or wherever.

the same single press of the same button then ALSO does the reverse !and goes to where the data is that you just wrote -and reads it then displays it.

If you are still confused dont panic...ther a re many really great people out here that could explain it a lot better than I just did.

Hope I helped ( even if just a little ) :)

_________________
Acer Aspire V touch
Opus Pro 9.51


Top
 Profile  
 
 Post subject:
PostPosted: December 8th, 2009, 6:35 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi,

Thanks for your reply.

At this point, with a deadline to meet, I think the best solution will be to write each variable to a separate text file, then read each variable back On PreShow. This produces a lot of text files, but I can place them all in one folder in the publication directory.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 8th, 2009, 10:03 pm 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Hi Stephen. Good cheer!

If you are reading whole sets of variables at one time, you can OpenFile() and then use ReadField(). When you write back the changed values, you need to navigate to the correct line (or other position ?).
Here's a ready example thanks to Mackavi and OpusLover. viewtopic.php?t=2688

If you want to update individual values or read different variables at different times, I would use an INI file. That way you could retrieve what you need by 'Section' or by field_identifier. Same applies to the writing to INI file.

A 'home-made' method could be this. Manually edit a file creating labels for your variables and then followed by some delimiter (e.g. ===>). Enter some default values and save the text file. Read-in the file to a local TextBox. Using String commands, it would be easy to 'find' the label and the position of its last character. Add +4 for the delimiter, then read the stored value to the end of the line. Use SetSelection() and ReplaceSelection() at runtime. (implies that you have the contents in a TextObject hidden or off-page, and then have to write back to file at appropriate times.) As an option, that TextObject could be on a MasterPage, so it is available for all Pub pages using the MP. (but you still need to write to disk to save it, etc.)

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: December 8th, 2009, 10:29 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Larry,

Thanks for your reply and suggestions. I'm about half way to constructing the individual text files for each to hold one variable's value. It's a round about way and harder, but all that I could do for now.

I took a look at the sample that you suggested with the link in your posting. It has a script to write 3 separate user inputs to a text file. That is 1/2 of what I need to do.

However, the second page is not completed, so there is currently no script for reading the sample IMP's 3 user input variables back into text boxes. But, if I can figure out the read back script, I may be able to apply it to my project. So, I will try to figure the read back script out.

(I would prefer to stay with a text rather than ini since I may need to encrypt the file for security.)

Again, thanks.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 12:34 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Quote:
so there is currently no script for reading the sample IMP's 3 user input variables back into text boxes

It has been a long time ago that I worked through this, so 'yes' it is possible it may be incomplete. However, I think all the 'how-to' pieces are there (see code piece below). It's also possible the page 2 you mention just needed a trigger or something to call the function that does the read?

Code:
function theReadFile()
{
  var objTextFile = OpenFile(SYSTEM_TEMP_DIR+"myUserTextInputFile.txt")
  userINPUT1 = objTextFile.ReadField()
  userINPUT2 = objTextFile.ReadField()
  userINPUT3 = objTextFile.ReadField()
  objTextFile.Close()
}


It seems that Opus automatically advances to the next 'field' -- which is nicely simple when you want to go thru the whole set.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 12:38 am 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Larry,

I had found that on page 1 when I searched further. I was able to get it to work by adding the read function as a script on page 2 and calling it on show.

Still experimenting to try to adapt it to my project. Should be relatively simple, but, so far, has been elusive. I'll keep at it.

Thanks,

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 1:03 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Good. Hope you can easily get it to work for you. Will check back.

Just remember:
Red wine -- for Read
White wine -- for Write
Brandy -- for Backup copy

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 1:52 am 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Larry,

Some success!!!

But a remaining challenge: if the user leaves one or more text input boxes blank, the script reads the next line, so variables become "detached" or out of sequence for their intended values.

The only solution I can think of would be to label each variable's data, then read back by using the labels: for example, if "Label C" then read back into variable C.

Not sure yet how to script this. Using 75-100 text files, each to store one variable's value, is beginning to look good again. :)

Again, thanks.

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 3:25 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Stephen

No worries.

Check back through that thread link.

I had had the same problem. The "null".
Quote:
If the User 'skips' inputting a response to TextInput1, the Read-in process on relaunch is incorrect. The NULL value in one TextInput box seems to throw off the series.


Opuslover (thank you) provided the solution. Perhaps I never closed the loop to include that corrected/updated script in the example? But its there.

Larry

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 4:16 am 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Hi Larry,

Yes, that seems to work.

My thanks to you and Opuslover.

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 6:29 am 
Offline
Godlike
Godlike

Joined: November 12th, 2005, 1:56 am
Posts: 1474
Location: SFBay Area
Opus: OpusPro v9.0x, & Evol.
OS: Vista32
System: Core 2 duo 2Ghz, RAM 3GB, Nvidia Go 7700 - laptop
Okay. It seems you've got it going.
The only 'hurdle' I see is in the handling of the tests for 'null', you will have 75 to 100 if_statements chained. Whew!!!

Maybe you could have a function that you could call... for each variable. Passing the name of the variable as an argument and inside the function just use the eval() command to test the 'null' condition and change the variable's value there.

_________________
_good things come to those who wait(0)_


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 9:21 am 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
For reference;

Rather than chaining all those variables, use an array and loop the index.

Also, the function to replace the empty string would be;

function replaceBlank(b)
{
if (b == "") return " "
else
{
return b
}

}

Used as such : objTextFile.WriteField(replaceBlank(userINPUT1))

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
 Post subject:
PostPosted: December 9th, 2009, 1:00 pm 
Offline
Godlike
Godlike

Joined: November 11th, 2004, 1:18 pm
Posts: 1213
Location: New York
Opus: Opus Pro 9.75
OS: Windows 10 Pro 64 bit
System: Core i7, 16G RAM, Nvidia 640GT (desktop), plus Windows 10 and Android tablets
Thanks, Mack.

Not sure I can figure arrays and loop through them, so for now, using the chained "if" statements. Fortunately, while maybe 75-100 total, not more than about 30 on any given page (and some ability to re-use the same scripts).

Kind Regards,

_________________
Stephen


Top
 Profile  
 
 Post subject:
PostPosted: December 9th, 2009, 1:22 pm 
Offline
Godlike
Godlike
User avatar

Joined: March 21st, 2007, 10:44 am
Posts: 3188
Location: UK
Opus: Evolution
Morning Stephen,

Something like;

for (var i=0;i<myArray.length;i++)
{
objTextFile.WriteField(replaceBlank(myArray[i]))
}

You simply create an array (called myArray) in the publication variables section and in each Text Input Box select the array and index.

Remember arrays start at zero.

Those two lines will loop through every input box and save the value.

Mack

_________________
When you have explored all avenues of possibilities, what ever remains, how ever improbable, must be the answer.

Interactive Solutions for Business & Education
Learn Anywhere. Learn Anytime.

www.interaktiv.co.uk
+44 (0) 1395 548057


Top
 Profile Visit website  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 55 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group