Jump to content

Recommended Posts

Posted

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:

 

'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

 

'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

Posted

OK as a total guess (not done vbs for years) it looks like your objOutput is creating a text file, I dont think that you can then use that declaration to give back information.

 

I'm not sure what you are attempting to do but if it is just displaying the path to the folder, why not create this as a variable that you can pass to the CreateTextFile method and then pass the variable into the message box?

Posted

From what I can see you are trying to write a textstream object to the msgbox rather than a path...

 

If you store the return from the InputBox in a variable you can use that to create the file and write the path to the msgbox...

 

[EDIT] Doh, got interrupted while typing my response and the got beaten to it... :doh: [/EDIT]

Posted
Ok, you can tell i'm a complete novice now :)

 

I have attached my current code as i'm still having problems with it :(

 

[ATTACH]12294[/ATTACH]

 

I hope someone can help me

 

You're not passing it a path, You're passing a string.

 

Simple example:

 

Dim objfso, objshell, objfolder, path, objoutput


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("Wscript.Shell")
Set objFolder = objFSO.GetFolder(InputBox ("Enter the full path to the folder","Enter Full Path","C:\test"))
path = InputBox("Enter the full path to the target file: ","Enter Full Path","C:\shortcuts.txt")

FullPath = objFSO.BuildPath(path, "")

Set objOutput = objFSO.CreateTextFile(FullPath)

 

Steve

Posted

Thank You Thank You Thank You Thank You Steve

 

I understand now, sorry if i was coming across as an idiot. First time doing anything like this but i'm enjoying it none the less.

 

Thanks again

Posted
Thank You Thank You Thank You Thank You Steve

 

I understand now, sorry if i was coming across as an idiot. First time doing anything like this but i'm enjoying it none the less.

 

Thanks again

 

No prob, If you get stuck on the rest just shout and I'll see what I can do, but hopefully that'll sort the rest.

 

Steve

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...