dScope prices from just US$4395/GB£3264 Request your personal on-line demo NOW!
Spectral Measurement Logo
Prism Sound Logo
  • Touch navigation
  • Home
    • News/Press
    • Offers
    • Corporate
    • Heritage
    • Events
    • Careers
    • Other Sites:
      • Recording and Production
      • Logging and Transcription
      • SADiE
      • Imerge
      • Audiophile
      • XiVA
    • Links
      • Reviews
      • Users
  • PRODUCTS
    • dScope Series IIIdScope
      Series III
      Digital and Analogue Audio Analyzer
    • dScope M1dScope
      M1
      Digital and Analogue Audio Analyzer
    • I/O SwitcherSwitcher
      dS-NET 16 x 2 I/O Switcher
    • VSIO adapterVSIO
      Digital Serial Interface Adapter
    • LPFdS-LPF
      Filter for digital amplifier tests
    • AutoTestSQL
      Production Test System
    • Auto Sequence
      Organizer, Automation & Reporting
    • TTC Loudspeaker Test ChamberTTC
      Loudspeaker Test Chamber
    • Other:
      • Recording and Production
      • Logging and Transcription
      • SADiE products
      • Imerge
      • Audiophile
  • APPLICATIONS
    • A/D and D/A conversion
    • Automotive Audio
    • Bluetooth Audio
    • Broadcast
    • Computer Audio
    • Education
    • Electro-acoustics
    • Home Entertainment
    • Manufacturing
    • Mobile Audio
    • Music Industry
    • Pro-Audio
    • R&D
    • Semiconductor
    • Service
  • SUPPORT
    • Support Home
    • FAQ
    • Downloads
    • Resources
    • Tech Support Form
    • Register Product
  • CONTACTS
    • Company Contact Info
    • Dealers and Distributors
    • Enquiry Form
    • Quotation Form
    • Mailing List Form
  • Home:
    • News/Press
      News stories and press releases
    • Offers
      Offers and promotions
    • Corporate
      Company information and history
    • Heritage
      Prism Sound heritage
    • Events
      Upcoming shows, exhibitions and events
    • Careers
      Jobs, careers and opportunities at Prism Sound
    • Other Sites:
      • Recording and Production
        Link to Prism Sound Recording and Production site
      • Logging and Transcription
        Link to Prism Sound Logging and Transcription site
      • SADiE
        Link to SADiE website
      • Imerge
        Link to Imerge website
      • Audiophile
        Link to Audiophile website
      • XiVA
        Link to XiVA website
    • Links
      Links to Prism Sound User's sites
      • Reviews
        Link to Prism Sound product reviews
      • Users
        Links to Prism Sound User's sites
  • PRODUCTS:
    • dScope Series IIIdScope
      Series III
      Digital and Analogue Audio Analyzer
    • dScope M1dScope
      M1
      Digital and Analogue Audio Analyzer
    • I/O SwitcherSwitcher
      dS-NET 16 x 2 I/O Switcher
    • VSIO adapterVSIO
      Digital Serial Interface Adapter
    • LPFdS-LPF
      Filter for digital amplifier tests
    • AutoTestSQL
      Production Test System
    • Auto Sequence
      Organizer, Automation & Reporting
    • TTC Loudspeaker Test ChamberTTC
      Loudspeaker Test Chamber
    • Other:
      • Recording and Production
        Recordind and Production products
      • Logging and Transcription
        Link to Prism Sound Logging and Transcription site
      • SADiE products
        Link to SADiE website
      • Imerge
        Link to Imerge website
      • Audiophile
        Link to Audiophile website
  • APPLICATIONS:
    • A/D and D/A conversion
    • Automotive Audio
    • Bluetooth Audio
    • Broadcast
    • Computer Audio
    • Education
    • Electro-acoustics
    • Home Entertainment
    • Manufacturing
    • Mobile Audio
    • Music Industry
    • Pro-Audio
    • R&D
    • Semiconductor
    • Service
  • SUPPORT:
    • Support Home
      Product technical support
    • FAQ
      FAQ's, Tips and Techniques
    • Downloads
      Software, Firmware and Manuals
    • Resources
      Reference material and downloadable resources
    • Tech Support Form
      Technical Support form
    • Register Product
      Studio products registration form
  • CONTACTS:
    • Company Contact Info
    • Dealers and Distributors
    • Enquiry Form
      Quick and Simple Enquiry Form
    • Quotation Form
      Request prices, loan or demo equipment
    • Mailing List Form
      Register for our mailing list

dScope Series III Scripting and automation

  • Overview
  • Features
  • Functions
  • Architecture
  • Automation
  • Tech Spec
  • FAQ
  • Downloads
  • Resources
  • Scripting
  • Accessories
  • Images

Generating HTML test reports from a script

VBScript is designed with web technology and generating HTML in mind. With a little knowledge of HTML it is possible to make well presented HTML reports and automatically generate an index file so that they are easy to access. The basics are the same as generating a text file, but with a few enhancements to allow better formatting.

When generating multiple HTML pages, it is most likely that you would like them all to have the same formatting. This means that bulk of each page will be the same, with just a bit of text in the middle that changes depending on the test results. An easy and efficient way to achieve this is to make a template page that has the required formatting (using an HTML editor of your choice) and then split it into two files at the place where you want to insert the results text. If you have server side scripting as an option, you can then save the results as separate files and re-combine the three files on the server to generate the output. Alternatively, if you do not have server side scripting, you can combine the files in the dScope script and save the output as complete HTML files which can then be read directly using any web browser. If the bulk of the formatting is defined in a CSS (Cascading Style Sheet) the resulting files can be quite small and look very good. This the approach we will be taking here. The discussion that follows assumes some knowledge of VBS and HTML.

Generating the HTML file
The first step is to start the File System Object and create a text file which we will call "HTMLFile" (it could be called anything, this is just the variable name we have chosen):

' Start the FSO
Set FSO = CreateObject("Scripting.FileSystemObject")

' create the text file object which we will call HTMLFile
Set HTMLFile = fso.CreateTextfile(strfilepath & strfilename, True)

In the example above, we have already defined two variables "strfilepath" (the path to the files we are working with) and "strfilename" (the name of the file we are generating). After this step, you can write to the newly generated text file by simply using the write method of the "HTMLFile" object like this:

HTMLFile.Write("The text you want to write goes here.<br>")
HTMLFile.Write("Add a bit more text here.")

This will result in the text as entered being added to the file. It would be possible to write the entire HTML file in this way by manually writing the header and footer with all the HTML tags, but it is easier to split the file into three and combine them as mentioned earlier. We can do this most efficiently by using a little function to retrieve the contents of the files as below. Here we are using the FSO again (it must already be open to run this function). The idea is that we are asking the function to return the entire contents of the file which we define by the string "strFile". The function first checks that the requested file exists. If it does, it will return the entire text of the file. If it doesn't, it will give a message box saying which file it couldn't find, and return an empty string.

'==========================================================
Function Get_File(strFile)
'==========================================================

'check whether the file exists
If FSO.fileexists(strFile) = false then
Msgbox "Missing file " & strfile, vbexclamation, "Missing File"
Get_File = ""
Exit Function
Else
Set TextFile = fso.OpenTextFile(strFile, 1) ' 1 = for reading
Get_File = TextFile.ReadAll()
TextFile.Close
Set TextFile = Nothing
End If

End Function

We can then use this function to combine our three files together. For the purposes of this discussion, we will assume that we have already split our template into two files called "RHeader.txt" and "RFooter.txt" which stand for Results Header and Results Footer.

'Write the header file contents into our new file
HTMLText.write Get_file(strfilepath & "RHeader.txt")

'Add the results
HTMLText.Writeline("<b>RESULTS</b><br>")
HTMLText.Writeline("Amplitude A = " & dAmplA & "dBu<br>")
HTMLText.Writeline("Amplitude B = " & dAmplB & "dBu<br>")

'Add the footer file
HTMLText.write Get_file(strfilepath & "RFooter.txt")

'Close the file and set the object to nothing
HTMLText.Close
Set HTMLText = Nothing

Depending on the content of the header and footer files, these few lines could generate a very neatly presented results page complete with graphics, links etc. The text could be entered in a <div> or <table> section of the page which would allow us to define additional formatting in the header and footer parts of the page and in any style sheet that is linked to from the header.

Making an HTML index file
It can also be helpful when making an HTML file to make an index page from where you can access the results. This can be made so that it updates automatically every time a new file is made. The FSO has methods for appending to a file and this is useful for adding a new result to a list. However, this is not that helpful for an HTML file as we don't actually want to write to the end of the file. An easy way to get round this is to make the index file in three parts as before. We will make header and footer template files again (and call them, "IHeader.txt" and "IFooter.txt" for Index header and Index Footer), but this time we will also use a text file (called index.txt) for the index part of the page. This time rather than generating it new each time, we will be using the "OpenTextFile" method to get the index text file and write to the end of it. This index text file will basically consist of a list of HTML links to which we will add a new link each time a new results page is generated.

The code to do this looks something like this:

'Update index text file
Set IndexFile = fso.OpenTextFile(strfilepath & "index.txt", 8, True)
IndexFile.Writeline "<a href='"& strfilename & "'>" & strID & "</a>"_
 & strDescription & "<br>"
IndexFile.Close
Set IndexFile = Nothing

'Create new index HTML file by combining the three files
Set IndexFile = fso.CreateTextFile(strfilepath & "index.html", True)
IndexFile.write Get_file(strfilepath & "IHeader.txt")
IndexFile.write Get_file(strfilepath & "index.txt")
IndexFile.write Get_file(strfilepath & "IFooter.txt")

'Close the file and set the object to nothing
IndexFile.Close
Set IndexFile = Nothing

Here "strID" is a string that identifies the test that is used as the link - it could just be the text "click here" etc. Also "strDescription" is a string that describes the test in more detail. It could be quite long, containing notes or serial numbers etc so as to distinguish between tests. All the preceding code assumes that the files are all in the same folder. It would be possible to build a more complex folder structure, but for simplicity, that is not what we have done here. And that's it. This gives you the basic technique, but there is really no limit to where you can take this using all the HTML, XHTML, PHP, CSS etc. technologies for generating web content.

Fixing the File Extension
Another little trick that is quite handy is to get the user to set the file name by using an input box after the test. If you do this, you don't know whether they are going to enter a file extension or not. To cope with this scenario, you can look for a full stop (".", AKA "period") in the string that is entered, strip off all the characters after that full stop and replace them with the characters HTML - this makes sure that the file name is always formatted correctly, irrespective of what file name is entered (as long as it doesn't actually contain full stops before the file extension, in which case you will end up with a shortened file name). The code to do this is:

' make sure we have the right file name extension
If instr(strfilename, ".") > 0 then 'file name contains a full stop
strfilename = left(strfilename, instr(strfilename, ".") - 1 )
End If
strfilename = strfilename & ".HTML"

Summary
The generation of HTML reports is a powerful and elegant way of keeping records. Generating reports in this way is very fast and there is almost no limit to what is possible. Linking in to an intra-net or posting results on a web site is very straight forward. However, it is not always the best way of doing things depending on the type of test data that is being recorded. Where you want to extract statistics from the data, saving to a spreadsheet or database would probably be a better option. Also, with very large numbers of files the indexes could become quite large. It wouldn't be too hard to automatically generate a layered file structure, perhaps based around separate indexes for years, months and days or some other metric which lends itself to logical operations and which subdivides the measured results.



info icon We're using a few cookies to make your visit here run smoothly. If you're happy with this, just continue to use the site as normal. To find out more, visit our cookie control page.

UK: +44 1353 648888




  Prism Media Products Limited trading as Spectral Measurement (formerly Prism Sound Test and Measurement); Registered in the UK, Reg. No. 2719511
  Address: Unit 1A, Grovemere House, Lancaster Way Business Park, Ely, Cambridgeshire, CB6 3NW, UK