![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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) Set oFSO = CreateObject("Scripting.FileSystemObject") You will also need to create an Application object. |
My System Specs![]() |
| | #3 (permalink) |
| | 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) Set oFSO = CreateObject("Scripting.FileSystemObject") Dirk |
My System Specs![]() |
| | #4 (permalink) |
| | 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) 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 Specs![]() |
| | #5 (permalink) |
| | 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 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 Specs![]() |
| | #6 (permalink) |
| | 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 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 Specs![]() |
| | #7 (permalink) |
| | 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 Specs![]() |
| | #8 (permalink) |
| | 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 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 Specs![]() |
![]() |
| 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 | |||