Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - runtime error: "Object required"

Reply
 
Old 02-16-2009   #1 (permalink)
karsagarwal


 
 

runtime error: "Object required"


Please help me. I am getting the following error on the 4th line of
the code: 'Object required: 'oFSO"
I have tried different things and it does not work.

Thanks,
SA


Sample code
-------------------
dim folderP, oFile, oFSO, fab
folderP=Application.PrimaryDirectory 'gives path of the project folder
C:\temp\Projects\21038Ax1aDx"
set oFile = oFSO.GetFile(folderP)
fab = mid(oFile.Name, 2, 4)

My System SpecsSystem Spec
Old 02-16-2009   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: runtime error: "Object required"


<karsagarwal@xxxxxx> wrote in message
news:a8b6d3d7-655d-4c5c-860b-75beba14d7c7@xxxxxx
Quote:

>
> Please help me. I am getting the following error on the 4th line of
> the code: 'Object required: 'oFSO"
> I have tried different things and it does not work.
>
> Thanks,
> SA
>
>
> Sample code
> -------------------
> dim folderP, oFile, oFSO, fab
> folderP=Application.PrimaryDirectory 'gives path of the project folder
> C:\temp\Projects\21038Ax1aDx"
> set oFile = oFSO.GetFile(folderP)
> fab = mid(oFile.Name, 2, 4)
You forgot to create the oFSO object:
Set oFSO = CreateObject("Scripting.FileSystemObject")
You will also need to create an Application object.


My System SpecsSystem Spec
Old 02-16-2009   #3 (permalink)
Dirk Stegemann


 
 

Re: runtime error: "Object required"

Hi,
Quote:

> Please help me. I am getting the following error on the 4th line of
> the code: 'Object required: 'oFSO"
> I have tried different things and it does not work.
>
> Thanks,
> SA
>
>
> Sample code
> -------------------
> dim folderP, oFile, oFSO, fab
> folderP=Application.PrimaryDirectory 'gives path of the project folder
> C:\temp\Projects\21038Ax1aDx"
> set oFile = oFSO.GetFile(folderP)
> fab = mid(oFile.Name, 2, 4)
i am missing something like...

Set oFSO = CreateObject("Scripting.FileSystemObject")

Dirk
My System SpecsSystem Spec
Old 02-16-2009   #4 (permalink)
Tom Lavedas


 
 

Re: runtime error: "Object required"

On Feb 16, 3:47*pm, "karsagar...@xxxxxx" <karsagar...@xxxxxx>
wrote:
Quote:

> Please help me. I am getting the following error on the 4th line of
> the code: 'Object required: 'oFSO"
> I have tried different things and it does not work.
>
> Thanks,
> SA
>
> Sample code
> -------------------
> dim folderP, oFile, oFSO, fab
> folderP=Application.PrimaryDirectory * *'gives path of the project folder
> C:\temp\Projects\21038Ax1aDx"
> set oFile = oFSO.GetFile(folderP)
> fab = mid(oFile.Name, 2, 4)
You need to instantiate an object before it is used (except for those
known to be provided by the host application). That is, in a
standalone WSH script you need a line like ...

set oFSO = CreateObject("Scripting.FileSystemObject")

In some other application, like Word or Excel as implied by your use
of Application - which is really VBA, not VBSscript), it can be done
in the same way, or by referencing the correct library and then using
early binding in the Dim statement, but that is out of scope here, I
think.

Of course, after you solve that problem, you're going to face others,
since I see at least two other syntax problems in the code snippet you
posted:

1. The line that reads [C:\temp\Projects\21038Ax1aDx"] is not valid
code, and

2. set oFile = oFSO.GetFile(folderP) will throw a run time error,
since the GetFile function expects the path to a FILE, not a folder.

You'll have to sort those out as well.

Good luck,

Tom Lavedas
My System SpecsSystem Spec
Old 02-16-2009   #5 (permalink)
karsagarwal


 
 

Re: runtime error: "Object required"

On Feb 16, 1:12*pm, "Dirk Stegemann" <dsgra...@xxxxxx> wrote:
Quote:

> Hi,
>
Quote:

> > Please help me. I am getting the following error on the 4th line of
> > the code: 'Object required: 'oFSO"
> > I have tried different things and it does not work.
>
Quote:

> > Thanks,
> > SA
>
Quote:

> > Sample code
> > -------------------
> > dim folderP, oFile, oFSO, fab
> > folderP=Application.PrimaryDirectory 'gives path of the project folder "C:\temp\Projects\21038Ax1aDx"
> > set oFile = oFSO.GetFile(folderP)
> > fab = mid(oFile.Name, 2, 4)
>
> i am missing something like...
>
> *Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> Dirk
Well, when I add the line as shown above it gives me a new error on

line 2: set oFile = oFSO.GetFile(folderP).

Error msg is " File not found". I don't understand what is missing
here but would like to add that folderP is just a variable that holds
the directory path and I need the 4 chars stating in position 2 from
the directory name. So I am thinking that I infact do not even need to
create a FileSystemObject or use the GetFile here.

For example if folderC is "C:\temp\Projects\21038Ax1aDx" I need to
extract 1038 from folderC.



Thanks,
SA.

My System SpecsSystem Spec
Old 02-16-2009   #6 (permalink)
Al Dunbar


 
 

Re: runtime error: "Object required"


<karsagarwal@xxxxxx> wrote in message
news:734ad3be-71a4-441d-bca2-7f53616c277d@xxxxxx
On Feb 16, 1:12 pm, "Dirk Stegemann" <dsgra...@xxxxxx> wrote:
Quote:

> Hi,
>
Quote:

> > Please help me. I am getting the following error on the 4th line of
> > the code: 'Object required: 'oFSO"
> > I have tried different things and it does not work.
>
Quote:

> > Thanks,
> > SA
>
Quote:

> > Sample code
> > -------------------
> > dim folderP, oFile, oFSO, fab
> > folderP=Application.PrimaryDirectory 'gives path of the project folder
> > "C:\temp\Projects\21038Ax1aDx"
> > set oFile = oFSO.GetFile(folderP)
> > fab = mid(oFile.Name, 2, 4)
>
> i am missing something like...
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
>
> Dirk
Well, when I add the line as shown above it gives me a new error on

line 2: set oFile = oFSO.GetFile(folderP).

===> since that looks more like line three, I'd suggest you reply with an
EXACT copy of the script as it now exists.

Error msg is " File not found". I don't understand what is missing
here but would like to add that folderP is just a variable that holds
the directory path...

===> that may be what you intended it to contain. But perhaps you should
display the value of the variable to make sure that the "Application" object
is returning what you think it should in its ".PrimaryDirectory" property.

and I need the 4 chars stating in position 2 from
the directory name. So I am thinking that I infact do not even need to
create a FileSystemObject or use the GetFile here.

For example if folderC is "C:\temp\Projects\21038Ax1aDx" I need to
extract 1038 from folderC.


===> FSO may indeed not be required, however, it does include various
methods for unambiguously extracting components of a path, like the base
file name. If you want to parse the full path name on your own go ahead.

/Al


Thanks,
SA.


My System SpecsSystem Spec
Old 02-16-2009   #7 (permalink)
Dirk Stegemann


 
 

Re: runtime error: "Object required"

Hi,

--
For example if folderC is "C:\temp\Projects\21038Ax1aDx" I need to
extract 1038 from folderC.
--

First of all i think it would be a good idea to read Tom's and Pegasus's replys carefuly.

I had to read about application.primaryFolder...
I think somthing similar to this would be app.path in vb or GetFolder(".")
This is the folder where the script resides.

here is a little sample....

Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(".")
MsgBox mid(oFolder.Name,2 ,4) ' Shows mid(2,4) of the actual folder
For Each sFolder In oFolder.Subfolders 'Walks the subfolders..
If MsgBox("mid (Foldername, 2,4) is """ & mid(sFolder.Name,2 ,4) & """" _
, 1, "OK") <> 1 _
Then WScript.Quit
Next

HTH

Dirk
My System SpecsSystem Spec
Old 02-16-2009   #8 (permalink)
Paul Randall


 
 

Re: runtime error: "Object required"


"Dirk Stegemann" <dsgrafik@xxxxxx> wrote in message
news:OAQ9vVIkJHA.5124@xxxxxx
Quote:

> Hi,
>
> --
> For example if folderC is "C:\temp\Projects\21038Ax1aDx" I need to
> extract 1038 from folderC.
> --
>
> First of all i think it would be a good idea to read Tom's and Pegasus's
> replys carefuly.
>
> I had to read about application.primaryFolder...
> I think somthing similar to this would be app.path in vb or GetFolder(".")
> This is the folder where the script resides.
>
> here is a little sample....
>
> Set oFSO = CreateObject("Scripting.FileSystemObject")
> Set oFolder = oFSO.GetFolder(".")
> MsgBox mid(oFolder.Name,2 ,4) ' Shows mid(2,4) of the actual folder
> For Each sFolder In oFolder.Subfolders 'Walks the subfolders..
> If MsgBox("mid (Foldername, 2,4) is """ & mid(sFolder.Name,2 ,4) & """"
> _
> , 1, "OK") <> 1 _
> Then WScript.Quit
> Next
Hi, Dirk
There are many ways to start a vbscript. For some of these ways,
oFSO.GetFolder(".") sometimes can return the folder object that contains the
script's source file. Of course, if the script has set up a WScript.Shell
object, it could change its CurrentDirectory property so that it no longer
matches the folder that contains the script. Or if the script is started by
dragging a file to the icon for the .vbs file, the current directory will
almost never be the folder that contains the script.

To get around these problems, I use code like this to set the current
directory to be the folder containing the script (after having created the
shell and fso objects):
objShell.CurrentDirectory = _
objFSO.GetParentFolderName(WScript.ScriptFullName)


My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
"Object required" message in VB Script VB Script
Runtime error and "IE stopped working" Vista General
Error: "Cannot convert "System.Object[]" to "System.Int32"." PowerShell
Keep getting error: "Microsoft visual basic c++ runtime library" Vista General
False IE doc body error - "Object reference not set to an instance of an object" PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46