p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   vbscript question (not sure where to post this) (http://p2p.wrox.com/showthread.php?t=38469)

interrupt February 14th, 2006 10:38 AM

vbscript question (not sure where to post this)
 
Hi all,

Not sure where to post this as its a web language but its VB orientated.

I have built a network upgrade app by combining VBScript with the NT4 Resource kit. I am trying at the moment to create a drop down list of available log files. Here's the code:

sub SaveLog(whichLog)

    set sObj = createobject("wscript.shell") 'create activeX shell obj
    serialTime = formatdatetime(now(), vblongdate) 'set up a date
    newdir = "c:\firestone_project\packaged\pastlogs\" 'set new location for file copy
    sObj.run("C:\winnt\system32\cmd.exe /c copy c:\firestone_project\packaged\ghostware-" & whichLog & ".log" & " " & chr(34) & newdir & whichLog & " " & serialTime & ".log" & chr(34) & " > c:\done.txt")'open command and run the copy

This is the easy part. The hard part is telling vbscript to populate a listbox WITHOUT duplicates consisting of all the .log files in the one directory. Here's the code:

    <script language = "vbscript">
    sub getLogs()
    set sObj = createObject("wscript.shell") 'create a shell to use with CMD
set fObj = createObject("scripting.filesystemobject")'Create a file system object
    sObj.run("c:\winnt\system32\cmd.exe /c dir c:\firestone_project\packaged\Pastlogs > c:\firestone_project\packaged\pastlogs\loglist.txt ") 'get DIR of all log files in the directory and output them to a textfile.

    set loglist = fObj.opentextfile("c:\firestone_project\packaged\p astlogs\loglist.txt")'open the textfile
do until loglist.atendofstream 'read it line by line passing each line of text into a select box option element
    theoption = loglist.readline
    set oElement = document.CreateElement("OPTION")
    oElement.text = theoption
    if instr(oElement.text, ".log")<> 0 then
    document.getElementById("selectlog").add oElement
    end if


    loop

    loglist.close


    end sub
    </script>

Whats happening is that every time my routine reads the loglist it duplicates it in the select box. Any ideas?



All times are GMT -4. The time now is 11:14 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.