A FileSystemObject that works on 2000 doesn't work in 98

I need to copy, open, create and delete files. I've got this method that works on my 2000 (compiler) but won't work in a 98. This method is in a module file (also tried a class file):

Public Sub WriteAFile()
    Dim o As Scripting.FileSystemObject
   
    On Error GoTo EnError
    Set o = New Scripting.FileSystemObject 'This line is where the error stops
    Dim buffer As TextStream
    Set buffer = o.CreateTextFile("scn.xc1")
    buffer.Write "1"
    buffer.Close
    Set o = Nothing
    Exit Sub
EnError:
    Set o = Nothing
    MsgBox Err.Description
End Sub


The error I get: "Class does not support automation or does not support expected interface"

If it is too imposible to get to work Scripting library (in 98) I'll accept as alternate answer code to do it by API and explanation of how to get help in those API (MSDN doesn't give anything)
ricarditopicaronAsked:
Who is Participating?
 
TimCotteeConnect With a Mentor Head of Software ServicesCommented:
Adding $ to the end of a function such as:

Dir() => Dir$() automatically tells VB that it should use the String version of the function rather than attempt to determine the datatype involved.

http://www.allapi.net is a greate place to look for API information.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
Check the version of the file on the Win2k and the Win98 pc, they will probably be different. Just copy the Win2k version to the Win98, register the file and there you go.

CHeers
0
 
inthedarkCommented:
Are you running an anti-virus program? Sometimes scripting can be disabled which causes some of the scripting objects not to work.

Try to disable virus protection just to rule out this possibility. If it makes no difference turn it back on quickly.




0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
inthedarkCommented:
In Norton Antivirus is called "Script Blocking".

After I discoverd this I used VB's own file handling.
0
 
inthedarkCommented:
Here are some functions you can place into a class:


MyData = ReadFile("C:\MyFolder\MyFile.txt")
Ok = WriteFileOK("C:\MyFolder\MyFile.txt", MyData)
OK = KillFileOK("C:\MyFolder\MyFile.txt")


To Scan a folder:

filename$ = Dir$(folder$ + "*.*")
Do While Len(filename$)>0
    Pathname=Folder$ + FileName$
    Gosub Process' to do
    Filename$ = Dir
Loop

The only problem with Dir is that you must store the folder contents before you move or delete a file.

Best of luck,

Nick....


Public Function ReadFile(FileName As String) As String

Dim wlfn As Long

wlfn = FreeFile
On Error Resume Next

If Len(Dir(FileName)) > 0 Then
    If Err.Number Then
        ReadFile = "Invalid resource file path: " + FileName
        Exit Function
    End If
   
    Open FileName For Input Shared As #wlfn
    ReadFile = Input(LOF(wlfn), wlfn)
    Close wlfn
Else
    ReadFile = "ERROR"
End If

End Function


Public Function WriteFileOK(FileName As String, DataString) As Boolean

Dim wlfn As Long

wlfn = FreeFile
On Error Resume Next
Err.Clear
WriteFileOK = False
Open FileName For Output As #wlfn
If Err.Number <> 0 Then
    Exit Function
End If
Print #wlfn, DataString;
Close wlfn
If Err.Number <> 0 Then
    Exit Function
End If
WriteFileOK = True

End Function

Function KillFileOK(FileName As String)
KillFileOK = True
If Len(Dir(FileName)) > 0 Then
    On Error Resume Next
    Kill FileName
    If Err.Number <> 0 Then
        KillFileOK = False
    End If
End If
End Function
0
 
inthedarkCommented:
I said:

The only problem with Dir is that you must store the folder contents before you move or delete a file.

But meant:

It is best to store the file names in a folder into an array before chaning the folder contents, as Dir can crash.
0
 
inthedarkCommented:
Nearly forgot, file copy in VB is easy:

FileCopy FromFileName, ToFileName
0
 
ricarditopicaronAuthor Commented:
Sory, I've made it work. I tried creating an OCX in Visual C++ with a method CreateAFile()(the only way I know to reach VC++ from VBasic), I inserted it on my VBasic project and made the package like that. Didn't work, (seems OCX don't have permission to write files), but the package installed a scrrun.dll that made the Scripting library work, so, sorry!, see ya!
0
 
ricarditopicaronAuthor Commented:
well, I cannot decline the question, so for finally getting the 500 points inthedark tell me:
filename$
dir$
folder$
What are this?
It made me remember about my old SVI728 MSX, are they strings? compatibility with old stuff (QBasic)?
0
 
ricarditopicaronAuthor Commented:
And something to look for API help it would help like how I use CopyFileA in Kernell32, how I look for that?
0
 
ricarditopicaronAuthor Commented:
A was waiting inthedark finish to answer my question, because his answer was difficult a didn't help me that much, but since you answered let say completing questions here are 500 points TimCottee
0
 
MindphaserCommented:
ricarditopicaron

Could you please explain why expert TimCotte only received a "C" grade for his answer? Please provide feedback if you are not happy with an answer and our experts will try to clarify their comments.
Here are the guidelines for grading:

A: The Expert(s) either provided you with a thorough answer or they provided you with a link to information that thoroughly answered your question. An "A" can also be given to any answer that you found informative or enlightening beyond the direct question that you asked.

B: The Expert(s) provided an acceptable solution, or a link to an acceptable solution, that you were able to use, although you may have needed a bit more information to complete the task.

C: Because Experts' reliability are often judged by their grading records, many Experts would like the opportunity to clarify if you have questions about their solutions. If you have given the Expert(s) ample time to respond to your clarification posts and you have responded to each of their posts providing requested information; or if the answers, after clarification, lack finality or do not completely address the issue presented, then a "C" grade is an option. You also have the option here of just asking Community Support to delete the question.

** Mindphaser - Community Support Moderator **
0
 
MindphaserCommented:
It seems ricarditopicaron doen't want to comment on this.

I will change the grade to 'A'.

** Mindphaser - Community Support Moderator **
0
 
programminglifeCommented:
Check the files whether is in a NTFS file format Disk, if so, you can move the files into another Disk!!!

Do you anderstand my opnion!

There are some error in my language!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.