http://www.microsoft.com/downloads/details.aspx?FamilyId=01592C48-207D-4BE1-8A76-1C4099D7BBB9
See the Textstream object for reading and
writing files. You can use it without problem
from within an HTA.
There are simple examples here:
http://technet.microsoft.com/en-us/library/ee198715.aspx
All you needed to do was to try something like
vbscript write file
at Google.
Thanks Mayayana but when I attempt it like that I get runtime errors;
Can you suggest another possibility?
Thnaks,
cisco
<html>
<head>
<title>Phone Numbers</title>
<HTA:APPLICATION
ID="objHTA"
APPLICATIONNAME="Scanners"
SCROLL="yes"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT Language="VBScript">
Sub Window_Onload
LoadDropDown
End Sub
''''''''''''''''''''''''''''''''
'''Attempt Creating files'''''
''''''''''''''''''''''''''''
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("script.txt", ForWriting)
objFile.Write Now
objFile.Close
'''''''''''''''''''''''''''''''''''''''''''''
Sub LoadDropDown
ClearListBox
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFile = objFS.OpenTextFile("Oracle.txt")
strScanners = objFile.ReadAll
objFile.Close
arrScanners = Split(strScanners, vbNewLine)
For Each strNumber in arrScanners
Set objOption = Document.createElement("OPTION")
objOption.Text = strNumber
objOption.Value = strNumber
Scanners.Add(objOption)
Next
End Sub
Sub ClearListbox
For Each objOption in Scanners.Options
objOption.RemoveNode
Next
End Sub
Sub TestSub
For Each objOption in Scanners.Options
If objOption.Selected Then
intAnswer = Msgbox (objOption.InnerText, VBYesNo, "Do you want
to delete this Scanner?")
If intAnswer = vbYes Then
Msgbox "You answered yes."
'''''''''''''''''''
Msgbox "this is correct " & objOption.value
''''''''''''''''''''''''''''''''
''''''''Creating files'''''''''''
'''''''''''''''''''''''''''''''''
'Const ForReading = 1, ForWriting = 2, ForAppending = 8
'Set objFSO = CreateObject("Scripting.FileSystemObject")
'Set objCreatedFile = objFSO.CreateTextFile("servers.txt", True)
'wscript.sleep 1000
'objCreatedFile.Close
'Set objOpenedFile = objFSO.OpenTextFile("servers.txt", ForWriting,
True)
'Set objShell = CreateObject("Wscript.Shell")
'''''''''''''''''''''''''''''''
'''''''''''''''''''
Else
Msgbox "You answered no."
LoadDropDown
End If
End If
Next
End Sub
</SCRIPT>
<body>
<select onActivate=LoadDropDown name="Scanners"
onChange="TestSub">
</select>
</body>
</html>
Is that the problem code? You have lots of code there,
with some of it commented out, and you didn't say
which code or what error was happening. It's best if
you can narrow down the line where it happens and
provide the error code. If the problem is in the code
above then I'm guessing you didn't create the file.
And you didn't provide the Boolean Create value.
If the file is not existing you need either:
OpenTextFile("script.txt", ForWriting, True)
or
CreateTextFile("script.txt", True) 'True to overwrite existing copy.
Also, you probably know this already, but not using
a full path only works in HTAs. It works in an HTA to
access a file in the same location, just as
<IMG SRC="pic.jpg" will look for [HTA path]\pic.jpg.
But if you tried that in a .VBS it goes batty. Out of
curiosity I tried it with Filemon running and saw that
wscript was trying to access
C:\Documents and Settings\[username]\\script.txt
Not only is the "\\" very odd, but I ran the script from
TEMP. I would have expected it to look in TEMP,
C:\, or the personal docs folder. Instead it looked
in the top level of the personal folder. (XP)
There were some missing arguments in the file manipulation statements
that I marked with comments in the procedure below (works for me) ...
<html>
<head>
<title>Phone Numbers</title>
<HTA:APPLICATION
ID="objHTA"
APPLICATIONNAME="Scanners"
SCROLL="yes"
SINGLEINSTANCE="yes"
</head>
<SCRIPT Language="VBScript">
' Declare global variables here
Dim objFSO
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Sub Window_Onload
''''''''''''''''''''''''''''''''
'''Attempt Creating files'''''
''''''''''''''''''''''''''''
' This creates the FSO globally, so it doesn't need to be
'instantiated again
Set objFSO = CreateObject("Scripting.FileSystemObject")
' This line was missing an argument to force creation of the file
' if it didn't already exist.
Set objFile = objFSO.OpenTextFile("script.txt", ForWriting, true)
objFile.Write Now
objFile.Close
'''''''''''''''''''''''''''''''''''''''''''''
LoadDropDown
End Sub
Sub LoadDropDown
ClearListBox
' This line was missing the input mode argument (ForReading constant)
Set objFile = objFSO.OpenTextFile("Oracle.txt", ForReading)
strScanners = objFile.ReadAll
objFile.Close
arrScanners = Split(strScanners, vbNewLine)
For Each strNumber in arrScanners
Set objOption = Document.createElement("OPTION")
objOption.Text = strNumber
objOption.Value = strNumber
Scanners.Add(objOption)
Next
End Sub
Sub ClearListbox
For Each objOption in Scanners.Options
objOption.RemoveNode
Next
End Sub
Sub TestSub
For Each objOption in Scanners.Options
If objOption.Selected Then
intAnswer = Msgbox (objOption.InnerText, VBYesNo, _
"Do you want to delete this Scanner?")
If intAnswer = vbYes Then
Msgbox "You answered yes."
'''''''''''''''''''
Msgbox "this is correct " & objOption.value
''''''''''''''''''''''''''''''''
''''''''Creating files'''''''''''
'''''''''''''''''''''''''''''''''
'
' I assume you were just testing things out here, because a created
' file is immediately available for use, without reopening it
'
'Set objCreatedFile = objFSO.CreateTextFile("servers.txt", True)
'wscript.sleep 1000
'objCreatedFile.Close
'Set objOpenedFile = objFSO.OpenTextFile("servers.txt", ForWriting,
True)
'Set objShell = CreateObject("Wscript.Shell")
'''''''''''''''''''''''''''''''
'''''''''''''''''''
Else
Msgbox "You answered no."
LoadDropDown
End If
End If
Next
End Sub
</SCRIPT>
<body>
<select onActivate=LoadDropDown name="Scanners"
onChange="TestSub">
</select>
</body>
</html>
__________________________
Tom Lavedas