Al Dunbar
1/23/2009 10:31:00 PM
"Paul Randall" <paulr90@aol.com> wrote in message
news:eRQfqtXfJHA.5956@TK2MSFTNGP06.phx.gbl...
>
> "Al Dunbar" <alandrub@hotmail.com> wrote in message
> news:eaENxDWfJHA.3776@TK2MSFTNGP03.phx.gbl...
>>
>> "Joe Fawcett" <joefawcett@newsgroup.nospam> wrote in message
>> news:%23qZavrUfJHA.1288@TK2MSFTNGP02.phx.gbl...
>>>
>>> "Paul Randall" <paulr90@aol.com> wrote in message
>>> news:uWGEjpSfJHA.4868@TK2MSFTNGP05.phx.gbl...
>>>> Hi,
>>>> Background: I'm working on building a VBScript that can build a series
>>>> of HTAs that display individual groups of pictures from a camera's
>>>> flash card. My script currently builds a list of all the pictures on
>>>> the flash card, sorted by date/time, and then splits the list into
>>>> groups where a new group is started any time there is an interval of at
>>>> least an hour between pictures. I think a gap of an hour is a good
>>>> indicator that the subject may have changed. Info from these group
>>>> lists are put into the bodies of group HTAs, which look like this:
>>>> <body>
>>>> 1 of 3 9/8/2008 4:12:00 PM DSC_0181.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0181.JPG"><br>
>>>> 2 of 3 9/8/2008 4:13:00 PM DSC_0182.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0182.JPG"><br>
>>>> 3 of 3 9/8/2008 4:13:00 PM DSC_0183.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0183.JPG"><br>
>>>> This group size: 4,319,651<br>
>>>> </body>
>>>>
>>>> Now that these group HTAs are displaying properly, I want to make it
>>>> possible for the photographer to add or edit a multi-sentence
>>>> description for the whole group of pictures and perhaps for each
>>>> picture. It seems to me it should be possible to use the onload event
>>>> to build a dropdown list of the IDs of the description IDs, so that
>>>> load and save buttons and a common editable text box can be used to
>>>> edit any of the description divisions. I have worked out logic to save
>>>> this self-modified HTA to the file path it was loaded from, as in the
>>>> HTA listing below. My intent is to have the photographer (or others)
>>>> to be able to run the VBScript that builds the group HTAs, then run
>>>> each of the HTAs and add any desired descriptions, and then write the
>>>> group HTAs and pictures to CD/DVD for archival.
>>>>
>>>> I'm thinking this might also be an easy way to pass around CD/DVDs
>>>> containing scans of old pictues to a select group of relatives who
>>>> might be able to add interesting commentary to the pictures in group
>>>> HTAs (but they would have to email the modified HTAs to some central
>>>> location to build an integrated set of HTAs & pictures, since writing
>>>> it back to the CD/DVD would be difficult).
>>>>
>>>> I'm hoping to get constructive criticism as to whether the project is
>>>> doable and perhaps sample code to collect the info needed from the
>>>> description DIVs to build a dropdown selection, and buttons to move
>>>> (load/save) the descriptions between their divisions and an editable
>>>> text box.
>>>>
>>>> Here is the current version of the HTA; it is also included as an
>>>> attachment (remove the .txt):
>>>> Note that one line, <HTA:APPLICATION id="oMyHTA" APPLICATIONNAME="My
>>>> App" SCROLL="yes" SINGLEINSTANCE="no" WINDOWSTATE="">
>>>> </HTA:APPLICATION>, has to be one long line because a multiline version
>>>> of it will be converted back to one long line by the
>>>> Self.document.all.item(0).Outerhtml property. I'm hoping to use a
>>>> comparison of the Outerhtml at window onload and unload times to decide
>>>> whether to ask the user if the HTA should be saved.
>>>>
>>>> Note too that the current version saves the the document's HTML at
>>>> window onload time with either 'yyy' or 'xxx' added, to prove that it
>>>> actually was changed.
>>>>
>>>> <HTML XMLNS:HTA><HEAD><TITLE>Self Modifying HTA</TITLE>
>>>> <SCRIPT language=vbscript>
>>>> 'Putting this script here prepositions the window.
>>>> 'Windowstate=Maximize would override this.
>>>> 'Global Variables:
>>>> Dim sOriginalHTA, sSourcePath
>>>> Const wdDlg = 600, htDlg = 380 ' dialog size
>>>> Const pxLeft = 100, pxTop = 100 ' positioning
>>>> window.ResizeTo wdDlg,htDlg
>>>> window.MoveTo pxLeft,pxTop
>>>> </SCRIPT>
>>>> <HTA:APPLICATION id="oMyHTA" APPLICATIONNAME="My App" SCROLL="yes"
>>>> SINGLEINSTANCE="no" WINDOWSTATE=""> </HTA:APPLICATION>
>>>>
>>>> <SCRIPT language=VBScript>
>>>> Sub Window_Onload
>>>> sOriginalHTA = Self.document.all.item(0).Outerhtml
>>>> sSourcePath = Split(UnEscape(Self.location), "///")(1)
>>>>
>>>> 'Write the contents of the HTA source back to its original file,
>>>> ' adding xxx or yyy depending on whether it is Unicode or
>>>> ' ASCII.
>>>> With CreateObject("Scripting.FileSystemObject")
>>>> On Error Resume Next
>>>> .CreateTextFile(sSourcePath, True, False). _
>>>> Write(sOriginalHTA & "yyy")
>>>> If Err Then
>>>> 'In case modifications include Unicode characters
>>>> On Error GoTo 0
>>>> .CreateTextFile(sSourcePath, True, True). _
>>>> Write(sOriginalHTA & "xxx")
>>>> End If
>>>> On Error GoTo 0
>>>> End With
>>>>
>>>> 'Read it into a string and see if anything changed.
>>>>
>>>> sTemp = include(sSourcePath)
>>>> msgbox "A difference of 'xxx' or 'yyy' indicates " & _
>>>> "the original source code was replaced, " & _
>>>> "using Unicode or ASCII write, respectively" & vbCrLf & _
>>>> "Difference is: " & replace(sTemp, soriginalhta, "")
>>>> End Sub
>>>>
>>>> Function include(sFileName)
>>>> 'Return a string containing the entire contents of
>>>> ' the specified file.
>>>> Dim objFSO
>>>> Dim objFile
>>>> Set objFSO = CreateObject("Scripting.FileSystemObject")
>>>> On Error Resume Next
>>>> Set objFile = objFSO.OpenTextFile(sFileName)
>>>> If Err then
>>>> Msgbox "Quitting - file " & sFileName & " can not be included."
>>>> Wscript.Quit
>>>> End If
>>>> On Error GoTo 0
>>>> include = objFile.ReadAll()
>>>> objFile.Close
>>>> End Function 'include(FileName)
>>>> </SCRIPT>
>>>> </HEAD>
>>>> <BODY>
>>>> <div id="GroupDescription">Description of group goes here
>>>> </div><br>
>>>> 1 of 3 9/8/2008 4:12:00 PM DSC_0181.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0181.JPG"><br>
>>>> <div id="1">Caption/commentary For picture 1</div><br>
>>>> 2 of 3 9/8/2008 4:13:00 PM DSC_0182.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0182.JPG"><br>
>>>> <div id="2">Caption/commentary For picture 2</div><br>
>>>> 3 of 3 9/8/2008 4:13:00 PM DSC_0183.JPG<br>
>>>> <img src="file://e:\DCIM\100NCD80\DSC_0183.JPG"><br>
>>>> <div id="3">Caption/commentary For picture 3</div><br>
>>>> </BODY>
>>>> </HTML>
>>>>
>>>> Thanks for any help you can give me.
>>>>
>>>> -Paul Randall
>>>>
>>>>
>>>
>>> I think it's doable. I'm not sure that it wouldn't be better to use a
>>> more traditional method, that of a datastore and a single HTA.
>>> The datastore, an XML document for example, would represent the images
>>> and their groups and also have the descriptions and any other metadata
>>> associated with them. The your HTA would have two modes. One that
>>> created the XML and one that read a nominated XML and displayed the
>>> appropriate images and text.
>>> This way you have only one version of the HTA, not hundreds, the
>>> downside is you need two files for it to work as well as the images.
>>
>> Self-modifying code can be difficult to debug. Have you looked into
>> leaving the code as-is but making use of DHTML techniques?
>>
>> /Al
>
> Hi, Al
>
> Perhaps I didn't explain it well enough. An HTA can contain data and HTML
> tags to format that data, and script code to do various functions. In
> this application the HTA's script code doesn't change -- only the info in
> the description DIVs would be modified (and saved in the original HTA
> file) each time the HTA is run and saved.
This approach (a script that modifies the content of the file in which it is
contained) can still be problematic. It could be argued that this still
qualifies as self-modifying code, in the same way that changing a line like
this:
name = "bill"
to this:
name = "dave"
is a change to the "code". In your case the data being modified is not
embedded into the "script code" per se, but data embedded between DIV tags.
While that might make an interesting discussion on a theoretical level, it
doesn't advance your problme much farther ;-)
> I agree that self-modifying code can be a real pain, and I think I need
> to add code to preserve a backup of the original HTA in case something
> goes wrong. I think modifying the DIV content is a DHTML technique. What
> DHTML techniques did you have in mind?
DHTML doesn't change what actually exists within a DIV tag (or any
scriptable object in the page). Rather it changes how the page is rendered
by making the HTML code that is emitted to the browser conditional on what
the script decides to do.
That said, I'm extremely rusty, so have little specific detail to provide
other than the suggestion youconsider DHTML.
/Al