Windows Vista Forums

Naming a text file from a selection in a listbox
  1. #1


    KBJM Guest

    Naming a text file from a selection in a listbox

    Is it possible to have a text file named per a selection from a list box. I
    am writing the script to list all the pcs in the offic.....created an html
    file to load the list box and I select the computer and have the script run
    giving me all the information I wanted....

    in the vbs file here is what i am using to name the text file...

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile("c:\Scripts\inventory.txt")

    But I want "inventory.txt" to be named "k42.txt" because I selected that
    from the list of computers.....

    <select size="4" name="Listbox1">
    <option value="k42">k42</option>
    <option value="mtj27">mtj27</option>
    <option value="mtj26">mtj26</option>



      My System SpecsSystem Spec

  2. #2


    James Whitlow Guest

    Re: Naming a text file from a selection in a listbox

    "KBJM" <KBJM@xxxxxx> wrote in message
    news:22D62D71-6F54-402B-8BAD-586282287319@xxxxxx

    > Is it possible to have a text file named per a selection from a list box.
    > I
    > am writing the script to list all the pcs in the offic.....created an html
    > file to load the list box and I select the computer and have the script
    > run
    > giving me all the information I wanted....
    >
    > in the vbs file here is what i am using to name the text file...
    >
    > Set objFSO = CreateObject("Scripting.FileSystemObject")
    > Set objTextFile = objFSO.CreateTextFile("c:\Scripts\inventory.txt")
    >
    > But I want "inventory.txt" to be named "k42.txt" because I selected that
    > from the list of computers.....
    >
    > <select size="4" name="Listbox1">
    > <option value="k42">k42</option>
    > <option value="mtj27">mtj27</option>
    > <option value="mtj26">mtj26</option>
    See if this is along the lines of what you are looking for:

    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Option Explicit

    Dim oIE, oWSH, i, sSelected, bIE, objFSO, objTextFile

    Set oIE = WScript.CreateObject("InternetExplorer.Application", "IE_")
    Set oWSH = CreateObject("WScript.Shell")
    oIE.navigate "about:blank"
    Do Until oIE.ReadyState = 4
    WScript.Sleep 100
    Loop
    oIE.StatusBar = False
    oIE.Toolbar = False
    oIE.document.title = "Example"
    oIE.visible = True
    For i = 1 to 10
    If oWSH.AppActivate(oIE.document.title) Then Exit For
    WScript.Sleep 100
    Next
    oWSH.AppActivate oIE.document.title

    With oIE.document.body
    .innerHTML = "<select size='4' name='Listbox1'>" _
    & "<option value='k42'>k42</option>" _
    & "<option value='mtj27'>mtj27</option>" _
    & "<option value='mtj26'>mtj26</option>" _
    End With

    oIE.document.all.Listbox1.onChange = GetRef("Selected")

    bIE = True
    Do While bIE
    WScript.Sleep 100
    Loop

    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.CreateTextFile("c:\Scripts\" & _
    sSelected & ".txt")

    Sub Selected
    sSelected = oIE.document.all.Listbox1.value
    bIE = False
    oIE.Quit
    End Sub

    Sub IE_onQuit
    If bIE Then WScript.Quit
    End Sub
    '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



      My System SpecsSystem Spec

Naming a text file from a selection in a listbox problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
File naming conventions used for EML files Scott L. Robik Live Mail 6 30 Mar 2010
Desktop Folder/File naming? gecko Vista General 1 15 Apr 2008
RC2 - Doc bug or file naming issue? Andrew Watt [MVP] PowerShell 1 12 Oct 2006
Naming a file with only an extension and no name cynistersix Vista General 1 13 Jun 2006
How to modify ListBox selection behavior Marcus Avalon 1 03 Apr 2006