Solved

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

Posted on 2002-07-08
14
197 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 142

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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now