Source language: Translate to:

Inserting data into html

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Inserting data into html

Postby Wrangler » Thu Mar 22, 2007 10:30 am

Can't figure this one out. I loop through a file and create an array:

FileLen "[pubdir]listprint.dat" "[flen]"
Loop "1" "[flen]" "[xx]"
FileRead "[pubdir]listprint.dat" "[xx]" "[bday[xx]]"
endloop

I want to display each line in a html file, with <BR> tag inserted after each line and put them all into one variable. I can then insert the contents of that variable in the html.

Any ideas?
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA

Postby Neosoft Support » Thu Mar 22, 2007 10:44 am

Couldn't you do something like this which doesn't require an array:

Code: Select all
SetVar "[HTML]" "<html>[#13][#10]<head>[#13][#10]</head>[#13][#10]<body>"
FileLen "[pubdir]listprint.dat" "[flen]"
Loop "1" "[flen]" "[xx]"
  FileRead "[pubdir]listprint.dat" "[xx]" "[bday]"
  SetVar "[HTML]" "[HTML][bday]<BR>[#13][#10]"
EndLoop
SetVar "[HTML]" "[HTML]</body>[#13][#10]</html>"


The carriage returns [#13][#10] are for readability and aren't really necessary.
NeoSoft Support
Neosoft Support
NeoSoft Team
 
Posts: 5603
Joined: Thu Mar 31, 2005 10:48 pm
Location: Oregon, USA

Postby beno » Thu Mar 22, 2007 10:46 am

Hi Wrangler,

It seems you need to accumulate/store the previous lines in your variable, something like:

Code: Select all

  SetVar "[MyOutput]" ""

  FileLen "[pubdir]listprint.dat" "[flen]"

    Loop "1" "[flen]" "[xx]"

      FileRead "[pubdir]listprint.dat" "[xx]" "[bday[xx]]"

      SetVar "[MyOutput]" "![MyOutput]<br>[bday[xx]]"

   endloop


My cent.

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby Gaev » Thu Mar 22, 2007 10:55 am

Wrangler:

If there is no ther reason for you to read the file one line at a time, you can just read the entire file into a variable ... and then replace all occurences of [#13][#10] with <br/> ... might need to add another <br/> at the very end of the last line ...
Code: Select all
FileRead "[pubdir]listprint.dat" "All" "[varListPrint]"
StrReplace "[varListPrint]" "[#13][#10]" "!<br/>" "[varListPrint]"

... may be required ...
SetVar "[varListPrint]" "![varListPrint]<br/>"

... say your template html file is template.htm
FileRead "[PubDir]template.htm" "All" "[varTemplate]"

... say the line data replaces a string like {insertLineDataHere}
StrReplace "[varTemplate]" "{insertLineDataHere}" "[varListPrint]" "[varTemplate]"
User avatar
Gaev
 
Posts: 3733
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby Wrangler » Thu Mar 22, 2007 11:33 am

Thanks guys for the input. Beno had the idea I was looking for since I have to read a file line by line to make it work.
Wrangler
--------------
"You never know about a woman. Whether she'll laugh, cry or go for a gun." - Louis L'Amour

Windows 7 Ultimate SP1 64bit
16GB Ram
Asus GTX 950 OC Strix
Software made with NeoBook
http://highdesertsoftware.com
User avatar
Wrangler
 
Posts: 1507
Joined: Thu Mar 31, 2005 11:40 pm
Location: USA


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 1 guest

cron