Solved

WScript.Arguments question

Posted on 2006-10-27
2
1,888 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

687 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