Monday, November 14, 2005

Why Don't You Just Tell Me What File?

I wrote a script and tried to make it easy. You could pick your input file and name your log file using common dialog boxes.

Now I have to re-write the script as a service, but I don't want to forget how to do this:

Option Explicit

'Confirm execution
Dim strScriptName, i
strScriptName = "My Script"
i = MsgBox ("Select an input file.", 1, strScriptName)
If i <> 1 Then
  i = MsgBox ("Script aborted.", 0, strScriptName)
  Wscript.Quit
End If

'Select the input file
Dim objCD, IntCD, strCD
Set ObjCD = CreateObject("UserAccounts.CommonDialog")
ObjCD.Filter = "Text Documents|*.txt|All Files|*.*"
ObjCD.FilterIndex = 1
IntCD = ObjCD.ShowOpen
If IntCD = False Then
  i = MsgBox ("No input file selected. Script aborted.", 0, strScriptName)
  Wscript.Quit
End If
strCD = objCD.FileName

'Select the log file
i = MsgBox ("Now select a log file.", 0, strScriptName)
Dim strLogFile, objLogFile, intLogFile
strLogFile = ObjCD.FileName & ".log"
Set objLogFile = CreateObject("SAFRCFileDlg.FileSave")
objLogFile.FileName = strLogFile
objLogFile.FileType = "Text Document"
intLogFile = objLogFile.OpenFileSaveDlg
If intLogFile Then
  strLogFile = objLogFile.FileName
Else
  i = MsgBox ("No log file selected. Script aborted.", 0, strScriptName)
  Wscript.Quit
End If

i = MsgBox ("Input File: " & strCD, 0, strScriptName)
i = MsgBox ("Output File: " & strLogFile, 0, strScriptName)

It works only on Windows XP, by the way!

No comments: