Showing posts with label vb script. Show all posts
Showing posts with label vb script. Show all posts

Jan 15, 2014

VB Script

I've needed to access an Access file from an html file. I did could do this using VBScript. It is running very well with Internet Explorer and could be a solutions in Corporatist offices wher security level is too paranoic.

Now I'm working with vbscripts. I use it to generate local xml files. Those xml files I use  to keep data from Access files to be easier to read in my network. The answer of my small app (.hta file) is much faster then if I read straight from MS Access file.

So, I used following code to generate a new .xml file:

<script type='text/vbscript'> 
        Set oFS = CreateObject("Scripting.FileSystemObject") 
           Const strXmlFile = "Documents.xml" 
           Set objXMLFile = oFS.OpenTextFile(strXmlFile, 2, True, 0) 
            objXMLFile.WriteLine "" 
            objXMLFile.WriteLine ""'" href=""Documents.xsl""?>" 
            objXMLFile.WriteLine "" 
           'Set myFolder = oFS.GetFolder("Documents") 
            'For Each File In myFolder.Files 
            'FileLast = File.DateLastModified 
            'FileMod = DateDiff("d", FileLast, Now) 
            '    If FileMod < 5 Then 
             'Corporate = File.Name 
             'myDate = Split(FileLast,"/") 
             'myYear = Left(myDate(2),4) 
             'myMonth = myDate(0) 
             'myURL = "Whatever your URL is" 
             'Download = "Wherever your download site is" 
             'Call CreateXML(Corporate,myYear,myMonth,myURL,Download) 
             Call CreateXML("Corporatia","myYear","myMonth","myURL","Download") 
              
                'End If 
            'Next 
           'This next call will run once the "CreateXML" has finished. 
           Call CloseXML() 
           Function CreateXML(Corporate,myYear,myMonth,myURL,Download) 
            objXMLFile.WriteLine vbTab & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & Corporate & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myYear & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myMonth & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & myURL & "" 
            objXMLFile.WriteLine vbTab & vbTab & "" & Download & "" 
            objXMLFile.WriteLine vbTab & "
"            End Function 
           Function CloseXML() 
            objXMLFile.WriteLine "
"              wscript.echo "Completed XML Creation" 
           End Function 

          </script>