Solved

VBS Script Modification Pt4

Posted on 2012-03-11
14
182 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
 

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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 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

14 Experts available now in Live!

Get 1:1 Help Now