Avatar of cpatte7372
cpatte7372
Flag for United Kingdom of Great Britain and Northern Ireland asked on

VBS Script Modification Pt4

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
Scripting Languages

Avatar of undefined
Last Comment
Meir Rivkin

8/22/2022 - Mon
Meir Rivkin

what's the error? which line?
cpatte7372

ASKER
sedgwick,

Thanks for responding. Attached is the error message.

Cheers

Carlton
scripterror2.jpg
Meir Rivkin

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 -
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
cpatte7372

ASKER
sedgwick,

having made the change I get the following error
scripterror3.jpg
Meir Rivkin

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

Meir Rivkin

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
cpatte7372

ASKER
Hi Sedgwick,

Thanks again for responding. I'm getting the attached error
scripterror4.jpg
Meir Rivkin

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

ASKER CERTIFIED SOLUTION
Meir Rivkin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
cpatte7372

ASKER
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
Your help has saved me hundreds of hours of internet surfing.
fblack61
Meir Rivkin

My mistake, replace the wscript line to:
 set g_shell=CreateObject(...
cpatte7372

ASKER
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
cpatte7372

ASKER
Thanks
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Meir Rivkin

10x for the points but why grade B?
My solution for u was spot on.