Solved

VBS Script Modification Pt4

Posted on 2012-03-11
14
191 Views
Last Modified: 2012-06-27
Can an Expert, please tell me why this script won't work?

# $language = "VBScript"
# $interface = "1.0"

Sub Main()

Dim szLogFilename
Dim g_szLogNameTemplate g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY -

HOST.log"
szLogFilename = g_szLogNameTemplate
szLogFilename = Replace(szLogFilename, "HOST", szHost)
szLogFilename = Replace(szLogFilename, "MM", NN(Month(Now)))
szLogFilename = Replace(szLogFilename, "DD", NN(Day(Now)))
szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

crt.session.logfilename = szLogFilename

End Sub

Cheers

Carlton
0
Comment
Question by:cpatte7372
  • 8
  • 6
14 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 37706727
what's the error? which line?
0
 

Author Comment

by:cpatte7372
ID: 37706786
sedgwick,

Thanks for responding. Attached is the error message.

Cheers

Carlton
scripterror2.jpg
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37706803
change this line:

Dim g_szLogNameTemplate g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY -

to this line:

Dim g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY -
0
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

Author Comment

by:cpatte7372
ID: 37706819
sedgwick,

having made the change I get the following error
scripterror3.jpg
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37706845
try this:


# $language = "VBScript"
# $interface = "1.0"

Sub Main()

Dim szLogFilename
set g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

szLogFilename = g_szLogNameTemplate
szLogFilename = Replace(szLogFilename, "HOST", szHost)
szLogFilename = Replace(szLogFilename, "MM", NN(Month(Now)))
szLogFilename = Replace(szLogFilename, "DD", NN(Day(Now)))
szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

crt.session.logfilename = szLogFilename

End Sub

Open in new window

0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37706849
btw, you can use FormatDateTime to format your date time in a single line without calling Replace on the string:

http://www.w3schools.com/vbscript/func_formatdatetime.asp
0
 

Author Comment

by:cpatte7372
ID: 37706872
Hi Sedgwick,

Thanks again for responding. I'm getting the attached error
scripterror4.jpg
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37706880
that was originally in your script, if i think that i know what u meant then try this:



# $language = "VBScript"
# $interface = "1.0"

Sub Main()

Dim szLogFilename
set g_shell = WScript.CreateObject("WScript.Shell") 
set g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

szLogFilename = g_szLogNameTemplate
szLogFilename = Replace(szLogFilename, "HOST", szHost)
szLogFilename = Replace(szLogFilename, "MM", NN(Month(Now)))
szLogFilename = Replace(szLogFilename, "DD", NN(Day(Now)))
szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

crt.session.logfilename = szLogFilename

End Sub
                                            

Open in new window

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 37706891
here's the script that should run without an error except you forgot to set the szHost variable.

Dim g_shell, g_szLogNameTemplate, szLogFilename
set g_shell = WScript.CreateObject("WScript.Shell") 
g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

szLogFilename = g_szLogNameTemplate
szLogFilename = Replace(szLogFilename, "HOST", szHost)
szLogFilename = Replace(szLogFilename, "MM", Month(Now))
szLogFilename = Replace(szLogFilename, "DD", Day(Now))
szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

MsgBox szLogFilename 

Open in new window

0
 

Author Comment

by:cpatte7372
ID: 37707574
Hi Sedgwick,


I added the script above as follows:


# $language = "VBScript"
# $interface = "1.0"

Sub Main()


Dim g_shell, g_szLogNameTemplate, szLogFilename
set g_shell = WScript.CreateObject("WScript.Shell")
g_szLogNameTemplate = g_shell.SpecialFolders("MyDocuments") & "\MM-DD-YYYY - HOST.log"

szLogFilename = g_szLogNameTemplate
szLogFilename = Replace(szLogFilename, "HOST", szHost)
szLogFilename = Replace(szLogFilename, "MM", Month(Now))
szLogFilename = Replace(szLogFilename, "DD", Day(Now))
szLogFilename = Replace(szLogFilename, "YYYY", Year(Now))

crt.session.logfilename = szLogFilename

MsgBox szLogFilename

End Sub


However I got the following error message, please see attached
scripterror5.jpg
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37707658
My mistake, replace the wscript line to:
 set g_shell=CreateObject(...
0
 

Author Comment

by:cpatte7372
ID: 37708020
Hi Sedgwick,

Sorry for not responding sooner. I have been working on another script that I have recently posted that is more important. I wonder if you can help me with it. Its VBS Modification PT6.

Would be great if you could assist me with that.

In the meantime, I will try your modification here.

Cheers

Carlton
0
 

Author Closing Comment

by:cpatte7372
ID: 37712371
Thanks
0
 
LVL 42

Expert Comment

by:sedgwick
ID: 37713168
10x for the points but why grade B?
My solution for u was spot on.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

756 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