Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 688

problem with loop

$
0
0
Hi I'm using this script to convert html file to mobi with mobigen.
It opens the opf template and set the author and the title of the books, and finally it makes an opf file that is used by mobigen.

Code:

Main()
WScript.Quit 0

Sub Main()
        Const ForReading = 1
        Const ForWriting = 2
        Const ForAppending = 8

        DIM booklistfile
        Dim book
        Dim bindestrich
        Dim author
        Dim title
        Dim opffile
        Dim opftemplate
        Dim opfcontent
        Dim opftemplatefile
        Dim opffilename

        Dim FSO
        Set FSO = CreateObject("Scripting.FileSystemObject")

        Dim oShell
        Set oShell = WScript.CreateObject ("WSCript.shell")

        Set opftemplatefile = FSO.OpenTextFile("template.opf", ForReading)
        opftemplate = opftemplatefile.Readline
        opftemplatefile.Close

        Set booklistfile = FSO.OpenTextFile("booklist.txt", ForReading)
        Do While (booklistfile.AtEndOfStream = False)
                book = booklistfile.Readline
                bindestrich = instr(book, " - ")
                if bindestrich = 0 or bindestrich = null then
                        author = "Unknown"
                        title = book
                else
                        author = Trim(Left(book, bindestrich - 1))
                        title = Trim(Right(book, Len(book) - bindestrich - Len(" - ") + 1))
                end if

                opfcontent = replace(opftemplate, "%1", title)
                opfcontent = replace(opfcontent,  "%2", author)
                opfcontent = replace(opfcontent,  "%3", book & ".html")

                opffilename = book & ".opf"
                Set opffile = FSO.CreateTextFile(opffilename, True)
                opffile.WriteLine(opfcontent)
                opffile.Close()

                oShell.run "mobigen " & """" & opffilename & """", 1, True
        Loop

        booklistfile.Close()
        Set FSO = Nothing
        Set oShell = Nothing
End Sub

I'd like to set book cover so I'm trying to edit the script in this way: basically I want to set a loop like the one used to create Title and Author data.
The script reads the first cover from cover.txt and then the author and title from booklist.txt and create the opf, then it reads the second cover and the second author and title and so on, creating an opf for each file.
I put a txt file that contains the list of the jpg images (they're stored in the same directory of html files, script and mobigen), named covers.txt and then this code before the title and author loop:
Code:

Set EmbeddedCover = FSO.OpenTextFile("00-cover.txt", ForReading)
Do While (EmbeddedCover.AtEndOfStream = False)
cover = EmbeddedCover.Readline

and then at the bottom:

opfcontent = replace(opfcontent, "00-cover.jpg", cover).

Unfortunately this script doesn't work and I can't fix it.
Do you think that is impossibile to add this feature or it's only a code problem?
Many thanks, Koundor

Viewing all articles
Browse latest Browse all 688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>