Solved

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

Posted on 2002-07-08
14
202 Views
Last Modified: 2011-09-20
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)
0
Comment
Question by:ricarditopicaron
  • 5
  • 4
  • 2
  • +3
14 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 7137353
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7137386
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7137422
In Norton Antivirus is called "Script Blocking".

After I discoverd this I used VB's own file handling.
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
LVL 17

Expert Comment

by:inthedark
ID: 7137442
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7137449
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
 
LVL 17

Expert Comment

by:inthedark
ID: 7137475
Nearly forgot, file copy in VB is easy:

FileCopy FromFileName, ToFileName
0
 

Author Comment

by:ricarditopicaron
ID: 7137506
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
 

Author Comment

by:ricarditopicaron
ID: 7137517
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
 

Author Comment

by:ricarditopicaron
ID: 7137523
And something to look for API help it would help like how I use CopyFileA in Kernell32, how I look for that?
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 7137542
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
 

Author Comment

by:ricarditopicaron
ID: 7140337
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
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7140932
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
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7154408
It seems ricarditopicaron doen't want to comment on this.

I will change the grade to 'A'.

** Mindphaser - Community Support Moderator **
0
 

Expert Comment

by:programminglife
ID: 7167558
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question