Advanced TIPS:Did you know that:
1. You already have a FILE OPEN PROMPT to open any file?
Yes, although it's not an Activ Script File Statement the HTML code provides you a way to do this, by using "<input type=file>".
Example:[code]
<form name="form1">
<input type="file" name="filename">
<input type="button" onClick="openFile(this.form.filename.value)" value="Open a File">
</form>[/code]
Then with a javascript function you can get the data from the file with an Activ Script or just display the contents of the file:
[code]<SCRIPT LANGUAGE="JavaScript">
function openFile(file) {
var fileToOpen = file;
// TO SEE THE FILE THAT WILL BE OPENED
alert("File to open: " + fileToOpen);
// THEN YOU CAN GET DATA FROM FILE USING AN ACTIV SCRIPT
// Add the file name to an Activ variable
window.external.ActivSet( 'FileName', file ) ;
// Read the file
window.external.ActivRun("#!read_file.as"
// Put the data retrieved from the file into a javascript variable
var FileData = window.external.ActivGet('{FileData}');
// Do whatever you want with the FileData variable
... code
// OR OPEN THE FILE CONTENTS IN THE BOOK
window.location= 'file:///' + file;
}
</SCRIPT>[/code]
The read_file.as can be something like:[code]
FILEREAD('isok','{FileData}','{FileName}')[/code]
Notes:
a) This is a simple javascript function. You can have off course code to test if file name is provided and to test if file was successfuly opened.
b) You cannot control the default directory to open the files. User must navigate to the directory to open it.
c) You should also limit the file types to be opened by checking the file extension. This feature allows users to open any type of file.
----------------------
2. INI files can be saved in other locations than the system file?
Just add the Predifined Directories and Drive letters variables before the INI file name.
Example to save the INI file in the the directory where the E-Book EXE file is located:
[code]INIWRITE('John Doe','{app}\userdata.ini','USER DATA','Name')
INIWRITE('johndoe@mail.com','{app}\userdata.ini','USER DATA','Email')[/code]
The ini file will have the following data:
[code][USER DATA]
Name=John Doe
Email=johndoe@mail.com[/code]
Activ Script INI Files Statement
INIWRITE(s1,s2,s3,s4)
s1 is the value to write.
s2 is the name of the INI file.
s3 is the application name to write the key under.
s4 is the key name
-----------------------
3. You can use INIWRITE to save files with a TXT extension?
Just change the .ini extension with .txt in the name of the file.
Example to save a txt file using INIWRITE in the eBook folder:
[code]INIWRITE('John Doe','{app}\userdata.txt','USER DATA','Name')
INIWRITE('johndoe@mail.com','{app}\userdata.txt','USER DATA','Email')[/code]
The beauty of this is that the txt file is saved in the same format as an INI file, in other words, you can store different application names each one with several keys and values. With same immagination and creativity you can create great eBooks with database files, by using this feature.
Note: INIWRITE currently allows you to save files with any extension.
Carlos
(Edited by Carlos at 9:41 pm on Jan. 29, 2003)