?
Solved

VBS Script Modification Pt4

Posted on 2012-03-11
14
Medium Priority
?
197 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: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
Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

 

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 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: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

How To Install Bash on Windows 10

Windows’ budding partnership with Canonical has certainly led to some great improvements. One of them being the ability to use Bash on your Windows machine without third party applications! This might be one of the greatest things a cloud engineer in a Windows environment can do!

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

770 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