Problem with MsgBox and Variables
Ok people
I am learning vbs coding from looking at others and then tweaking them to suit my purposes. I learn best this way you see. The problem I have is this.
I have located a vbs script to locate the shortcuts in a folder and return them and their targets and list them in a text file. It works perfectly however it is not very user friendly as you have to edit the script to change certain variables. To that end I have included an Input Box to ask the user where they want to scan and for the time being left the target file as a hardcoded location. Now the problem comes when including both these variables in a confirmation MsgBox.
This works:
Code:
'LocateSC.vbs
'' /// Setup environment declarations and object references ///
Dim path
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell = CreateObject("Wscript.Shell")
Dim objFolder:Set objFolder = objFSO.GetFolder(InputBox ("Enter the full path to the folder","Enter Full Path","C:\test"))
Dim objOutput:Set objOutput = objFSO.CreateTextFile("C:\Shortcuts.txt")
If MsgBox("This program will scan for shortcuts in your selected location - " & objFolder _
& vbNewline & vbNewline & "It will then list them in a text file under the following path - " _
& vbNewline & vbNewline & "Click Ok to Proceed.", vbOkCancel, "Shortcut Analyser") _
= vbOk Then
This doesn't
Code:
'LocateSC.vbs
'' /// Setup environment declarations and object references ///
Dim path
Dim objFSO:Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objShell:Set objShell = CreateObject("Wscript.Shell")
Dim objFolder:Set objFolder = objFSO.GetFolder(InputBox ("Enter the full path to the folder","Enter Full Path","C:\test"))
Dim objOutput:Set objOutput = objFSO.CreateTextFile("C:\Shortcuts.txt")
If MsgBox("This program will scan for shortcuts in your selected location - " & objFolder _
& vbNewline & vbNewline & "It will then list them in a text file under the following path - " & objOutput _
& vbNewline & vbNewline & "Click Ok to Proceed.", vbOkCancel, "Shortcut Analyser") _
= vbOk Then
If I try to run the second one I get the following error box:
Script: (path to script)
Line: 10
Char: 1
Error: Object doesn't support this property or method
Code: 800A01B6
Source Microsoft VBScript runtime error
Now I know that this means the error is on line 10 and that is the MsgBox code but what I don't understand is why if I remove the objOutput variable from the MsgBox script it works fine. If needed I can provide my script in it's current form.
Thanks for looking people