Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBS Script Modification Pt4

Posted on 2012-03-11
14
Medium Priority
?
200 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
[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
  • 8
  • 6
14 Comments
 
LVL 42

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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
Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

 

Author Comment

by:cpatte7372
ID: 37706819
sedgwick,

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

Expert Comment

by:Meir Rivkin
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:Meir Rivkin
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:Meir Rivkin
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:
Meir Rivkin earned 1500 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:Meir Rivkin
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:Meir Rivkin
ID: 37713168
10x for the points but why grade B?
My solution for u was spot on.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
Batch, VBS, and scripts in general are incredibly useful for repetitive tasks.  Some tasks can take a while to complete and it can be annoying to check back only to discover that your script finished 5 minutes ago.  Some scripts may complete nearly …
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
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…
Suggested Courses

604 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