Solved

WScript.Arguments question

Posted on 2006-10-27
2
1,878 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 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
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
Comment Utility
Thanks! just want I was  looking for.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

763 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now