Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Expected End of Statement" Around GetFile() and OpenAsTextStream()

Status
Not open for further replies.

joannadarling

Programmer
May 20, 2008
5
US
I am getting the "Expected End of Statement" error around line 9. I numbered the lines below so you can see

7 Dim FileObject = CreateObject("Scripting.FileSystemObject")
8 Dim UserFile = FileObject.GetFile("user.txt")
9 Dim UserStream = UserFile.OpenAsTextStream(2)

What could I be doing wrong??? I've tried specifying a full path instead of just saying "user.txt", but that isn't helping.

Any ideas?
 
OpenAsTextStream(2)

i think the 2 is giving you issues

the 2 should really be a text string in qoutes specifying the file to open? (unless you have declared 2 as a variable)
 
well just goes to show how rusty i am!!!

you should be fine with the 2, opening for writing.

do you have on error resume next? i am not used to seeing Dim statements followed by = assignments, perhaps this will work?


Dim FileObject, UserFile, UserStream
Set FileObject = CreateObject("Scripting.FileSystemObject")
Set UserFile = FileObject.GetFile("user.txt")
Set UserStream = UserFile.OpenAsTextStream(2)
 
mrmovie,
I do not have an on error resume next.

I will try what you said and let you know what happens! Thanks.
 
> Dim FileObject = CreateObject("Scripting.FileSystemObject")
This is not vbs declaration syntax. It is this instead.

[tt]Dim FileObject
set FileObject = CreateObject("Scripting.FileSystemObject")[/tt]

Similarly for the rest.
 
Same error! But, it told me line 9 again, even though the line numbers changed, which makes me think that my debugger doesn't work.

7 Dim FileObject, UserFile, UserStream
8 Set FileObject = CreateObject("Scripting.FileSystemObject")
9 Set UserFile = FileObject.GetFile("user.txt")
10 Set UserStream = UserFile.OpenAsTextStream(2)

I am using VbsEdit to create this script, but the thing that's actually telling me line 9 is the program I'm putting this script into. When I debug on VbsEdit, it doesn't give me a line number, just the error. Wow, how frustrating.

Any other ideas? How about ideas for free vbs editors that have more in depth error reporting?
 
>Set UserFile = FileObject.GetFile("user.txt")
To ensure this line is error free, you can do this for debugging. (It is not trying to be concise as such.)
[tt]
if FileObject.fileexists("user.txt") then
Set UserFile = FileObject.GetFile("user.txt")
else
Set UserFile=nothing
end if
if UserFile is nothing then
wscript.echo "no need to go further, check the file"
wscript.quit
end if
[/tt]
 
I found the problem. VbsEdit is actually a very nice program and it provided the line number where the error was at, it just wasn't labeled so I had no idea what it was, and it was in a "line, column" format, eg. (1, 19).

Anyway, the problem is what both of you guys mentioned, declaring and setting objects in the same line. As soon as I separated all the declarations from the setting of them, it worked.

Thanks so much for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top