PDA

View Full Version : How to put a variabele in a WriteFromString


brianlesker
10-01-2004, 05:28 AM
TextFile.WriteFromString("d:\\check_password.sql", [[
bla bla bla bla
want to put var in text file from SF7:

%var% or ..var.. or .......

quit
]], false);

Some one can help?

csd214
10-01-2004, 06:46 AM
Hi,

The string can have the content of a LUA variable. If the text is assigned to a Session Variable, you first have to expand it.


strMyText = SessionVar.Expand("%ProductName%".. " is installed in ".."%AppFolder%");
TextFile.WriteFromString("C:\\MyFile.txt", strMyText, false);
Dialog.Message("C:\\MyFile.txt","The text '"..strMyText.."' is now written to the file", MB_OK, MB_ICONNONE);

Session Variables are used for DISPLAYING purposes in the screens.

brianlesker
10-01-2004, 06:59 AM
i want to use a LUA var in a write.string thing (multiline). how to do then?

csd214
10-01-2004, 08:23 AM
Something like this?

strMyText = SessionVar.Expand("This text has".."\r\nbe displayed".."\r\non severel lines:".."\r\n".."\r\n%ProductName%".."\r\nis installed in".."\r\n%AppFolder%");
TextFile.WriteFromString("C:\\MyFile.txt", strMyText, false);

But now you have a very LONG code line. I prefer to break it up like this:

strMyText = SessionVar.Expand("This text has"
.."\r\nbe displayed"
.."\r\non severel lines:"
.."\r\n"
.."\r\n%ProductName%"
.."\r\nis installed in"
.."\r\n%AppFolder%");
Was this an answer to your question?

brianlesker
10-01-2004, 08:34 AM
Nope, i have the following code:

In this code cq text file, i want to use LUA vars...


TextFile.WriteFromString(strAppSqlDir.."\\check_password.sql", [[
WHENEVER OSERROR EXIT 32767
WHENEVER SQLERROR EXIT SQL.SQLCODE

SET pause off
SET heading off
SET feedback off
SET timing off
SET termout off
SET echo off
SET verify off
SET linesize 1000
SET pagesize 1000
TRIMSPOOL on

connect sys/oracle1@%DatabaseNaam%;
spool %AppSqlDir%\check_dbsyspass.txt
select 'Ja' from dual;
spool off
connect system/oracle1@%db_naam%;
spool %AppSqlDir%\check_dbsystempass.txt
select 'Ja' from dual;
spool off
connect impulse/%ImpPass%@%db_naam%;
spool %AppSqlDir%\check_dbimpulsepass.txt
select 'Ja' from dual;
spool off

quit
]], false);

csd214
10-01-2004, 08:38 AM
Nope?

You have another string than I have in my simple example, but the principle is the same.

Just edit your string, be aware of quotation marks, and add some "\r\n" [=CR|LF].

Lorne
10-01-2004, 08:50 AM
Nope, i have the following code:

In this code cq text file, i want to use LUA vars...
If I understand you correctly, you want to use lua variables instead of those session variables?

It looks to me like it would be easier just to use the session variables, and expand the whole string like this:


TextFile.WriteFromString(strAppSqlDir.."\\check_password.sql", SessionVar.Expand([[
WHENEVER OSERROR EXIT 32767
WHENEVER SQLERROR EXIT SQL.SQLCODE

SET pause off
SET heading off
SET feedback off
SET timing off
SET termout off
SET echo off
SET verify off
SET linesize 1000
SET pagesize 1000
TRIMSPOOL on

connect sys/oracle1@%DatabaseNaam%;
spool %AppSqlDir%\check_dbsyspass.txt
select 'Ja' from dual;
spool off
connect system/oracle1@%db_naam%;
spool %AppSqlDir%\check_dbsystempass.txt
select 'Ja' from dual;
spool off
connect impulse/%ImpPass%@%db_naam%;
spool %AppSqlDir%\check_dbimpulsepass.txt
select 'Ja' from dual;
spool off

quit
]]), false);


...but if you want to use lua variables instead, you can do so like this:


TextFile.WriteFromString(strAppSqlDir.."\\check_password.sql", [[
WHENEVER OSERROR EXIT 32767
WHENEVER SQLERROR EXIT SQL.SQLCODE

SET pause off
SET heading off
SET feedback off
SET timing off
SET termout off
SET echo off
SET verify off
SET linesize 1000
SET pagesize 1000
TRIMSPOOL on

connect sys/oracle1@]]..strDatabaseNaam..[[;
spool ]]..strAppSqlDir..[[\check_dbsyspass.txt
select 'Ja' from dual;
spool off
connect system/oracle1@]]..db_naam..[[;
spool ]]..strAppSqlDir..[[\check_dbsystempass.txt
select 'Ja' from dual;
spool off
connect impulse/]]..strImpPass.."@"..db_naam..[[;
spool ]]..strAppSqlDir..[[\check_dbimpulsepass.txt
select 'Ja' from dual;
spool off

quit
]], false);

csd214
10-01-2004, 11:13 AM
Lorne, I didn't know about the double angle brackets
[[
to create
a block of text
]]

Is it covered in the help doc? (I can't find it.)

Lorne
10-01-2004, 11:26 AM
It's on page 273 in the user's guide.

brianlesker
10-04-2004, 01:20 AM
csd214: that's easier than your "\r\n" [=CR|LF] :lol

csd214
10-04-2004, 02:44 AM
csd214: that's easier than your "\r\n" [=CR|LF] :lol
Yes, indeed (in your case). Once again Lorne had something to teach me; this forum is indispensable. :yes

(But the "\r\n" is working! I just tried to help you.)

SUF6NEWBIE
10-04-2004, 05:44 PM
You can also use the methods described to 'write-create' INI files
'on the fly'