?
Solved

WScript.Arguments question

Posted on 2006-10-27
2
Medium Priority
?
1,902 Views
Last Modified: 2013-12-25
this script will output my Arguments to a msgbox.
I'm tryingto figure out how(if there is a way) to have it save/output it to a file(txt) instead.

Thanks in advance,

'=============================================
Option Explicit
Dim vArg, aArgs(), iCount
If WScript.Arguments.Count = 0 then
MsgBox "No Arguments Supplied"
WScript.Quit
Else
ReDim aArgs(WScript.Arguments.Count - 1)
For iCount = 0 to WScript.Arguments.Count - 1
aArgs(iCount) = WScript.Arguments(iCount)
MsgBox aArgs(iCount)
Next
End If

Dim oShell, sLogEntry
Set oShell = CreateObject("WScript.Shell")
sLogEntry = "Script was run with :"
For iCount = 0 to UBound(aArgs)
sLogEntry = sLogEntry & vbCrLf & aArgs(iCount)
Next
oShell.LogEvent 4, sLogEntry
'==========================================

~Koolage
0
Comment
Question by:koolage
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 17821578
Something like...

Option Explicit

Dim vArg, aArgs(), iCount
If WScript.Arguments.Count = 0 then
    MsgBox "No Arguments Supplied"
    WScript.Quit
End If

Dim sLogEntry
sLogEntry = "Script was run with :" & vbCrLf
For iCount = 0 to WScript.Arguments.Count - 1
    sLogEntry = sLogEntry & WScript.Arguments(iCount) & vbCrLf
Next

Const ForReading = 1, ForWriting = 2
Dim fileName, fso, f
fileName = "c:\someFile.txt"
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(fileName, ForWriting, True)
f.Write(sLogEntry)  
f.Close
0
 

Author Comment

by:koolage
ID: 17834127
Thanks! just want I was  looking for.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month15 days, 10 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question