Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to display content of .txt file in wscript.echo? 2

Status
Not open for further replies.

TheNewOne

Technical User
Mar 27, 2004
117
SI
Hi forum. Anyone know if it's possible to display content of .txt file, which is located on local server in VB script message?? THX for any help

Jure, Slovenija
 
well to display a message you can either use

Wscript.Echo or Msgbox

to display the contents of a text file you have to open the file then do something like OpenAsTextStream or something like that.

 
Take a look at FileSystemObject.
A starting point:
WScript.Echo f.ReadAll

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hello TheNewOne,

This is to further illustrate what advised.
[1] As long as you get the share exposed on the local server, you can use fso to read the message file. If not, no.
[2] wscript.echo and/or msgbox do not have scoll bar control, so for message >50 or so line, it would be awkward.
Code:
filespec="\\a0b1c2\test\msgfile.txt"    'servername,share,msgfile
on error resume next
wscript.echo createobject("scripting.filesystemobject").opentextfile(filespec,1,false).readall
if err.number<>0 then wscript.echo "File not found." : err.clear
on error goto 0
(construction deliberately convolute)
[3] For long message, it is then you've found some control supporting scroll bar. Internet-explorer is an option. A simpler approach is to open it in notepad (the downside is that you can edit the message perhaps too easily.)
Code:
filespec="\\a0b1c2\test\msgfile.txt"    'servername,share,msgfile
on error resume next
createobject("wscript.shell").run "notepad.exe " & filespec
if err.number<>0 then wscript.echo "File not found." : err.clear
(construction deliberately convolute)

regards - tsuji
 
THX Tsuji for excelent solution. Script works perfect. Star for you. Thx PHV and mrmovie for advice. You rock guys!!!

Jure, Slovenija
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top