hi,
I have a vbscript that I can not get to recurs properly. If the user enters
'5' for input, the script should end. For ALL other input: invalid data
returns to the inputbox (this works), and valid data should execute the
corresponding sub-routines, and then return to the inputbox. I am unable to
format this so far to get it to do this. I have tried loops and ended up with
mostly endless loops. I have also tried to call (a 2nd call) the
sub-procedure for the main menu (mainmenu()) at the end of the script, but it
simply stops after the previous sub-routines finish. I have also tried to add
the mainmenu() call at the end of each sub-routine for option 1thru4 to no
avail, it still stops after each sub-routine.
The inputbox and the use of subroutines for the selections 1-4 are required,
so I can not re-write this entire thing. Any suggestions?
the script:
__________________________________________________________
Option Explicit
Dim fso, objshl, textfile, title, choice, inputtest, program, exitnow
Set fso = CreateObject("Scripting.FileSystemObject")
Set objshl = CreateObject("WScript.Shell")
textfile = "c:\scriptlog.txt"
title = "Main Menu - Current Date: " & Date
'*************************
'Main Processing Section *
'*************************
mainmenu()
If choice = "1" Then
Logfile()
Powerpoint()
ElseIf choice = "2" then
Logfile()
Excel()
ElseIf choice = "3" Then
Viewlogfile()
ElseIf choice = "4" then
Deletelogfile()
End If
'********************************************
'Main Menu for player input and value testing
'********************************************
Sub mainmenu()
Do Until inputtest = "valid"
choice = (InputBox(("1. Run PowerPoint") & vbCrLf & ("2. Run Excel")_
& vbCrLf & ("3. View Log File") & vbCrLf &_
("4. Delete Log File") & vbCrLf & ("5. Quit") & vbCrLf &_
vbCrLf & vbTab & vbTab & vbTab & "Choose By Number",title))
If choice = "1" Then
inputtest = "valid"
program = "PowerPoint"
ElseIf choice = "2" then
inputtest = "valid"
program = "Excel"
ElseIf choice = "3" Then
inputtest = "valid"
ElseIf choice = "4" then
inputtest = "valid"
ElseIf choice = "5" Then
WScript.Quit
Else MsgBox("Your selection was not valid")
End If
Loop
End Sub
'**********************************************
'Create 'start' logfile text for option 1 and 2
'**********************************************
Sub Logfile()
Dim log
If (fso.FileExists(textfile)) Then
Set log = fso.OpenTextFile(textfile,8)
log.WriteLine "-- -- -- -- -- -- -- -- -- -- -- --"
log.WriteLine ((program) & " started on ") & Date
log.WriteLine ((program) & " started at ") & Time
log.WriteLine "-- -- -- --"
log.close
Else
Set log = fso.OpenTextFile(textfile, 2, "true")
log.WriteLine "-- -- -- -- -- -- -- -- -- -- -- --"
log.WriteLine ((program) & " started on ") & Date
log.WriteLine ((program) & " started at ") & Time
log.WriteLine "-- -- -- --"
log.close
End If
End Sub
'**************************************
'Process tasks for option '1' selection
'**************************************
Sub Powerpoint()
Dim log
objshl.Run "powerpnt.exe",,True
Set log = fso.OpenTextFile(textfile, 8)
log.WriteLine "PowerPoint stopped on " & Date
log.WriteLine "PowerPoint stopped at " & Time
log.WriteLine "-- -- -- -- -- -- -- -- -- -- -- --"
log.close()
End Sub
'**************************************
'Process tasks for option '2' selection
'**************************************
Sub Excel()
Dim log
objshl.Run "excel.exe",,True
Set log = fso.OpenTextFile(textfile, 8)
log.WriteLine "Excel stopped on " & Date
log.WriteLine "Excel stopped at " & Time
log.WriteLine "-- -- -- -- -- -- -- -- -- -- -- --"
log.close()
End Sub
'**************************************
'Process tasks for option '3' selection
'**************************************
Sub Viewlogfile()
Dim output, log
Set log = fso.OpenTextFile(textfile, 1)
If (fso.FileExists(textfile)) Then
output = log.ReadAll
log.Close
MsgBox output
Else
MsgBox("The log file does not exist")
End If
End Sub
'**************************************
'Process tasks for option '4' selection
'**************************************
Sub Deletelogfile()
Dim confirm, file
If Not (fso.FileExists(textfile)) Then
MsgBox "There is no file to delete", 0
Else
confirm = MsgBox("Are you sure you wish to delete this?", 4, "Confirm
Selection")
If confirm = vbYes Then
fso.DeleteFile textfile
Set file = fso.OpenTextFile(textfile, 2, "true")
file.WriteLine "Logfile created on " & Date & " at " & Time
file.close
End if
End If
End Sub


