Solved

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

Posted on 2002-07-08
14
196 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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Nearly forgot, file copy in VB is easy:

FileCopy FromFileName, ToFileName
0
 

Author Comment

by:ricarditopicaron
Comment Utility
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:ricarditopicaron
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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 …
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

744 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

11 Experts available now in Live!

Get 1:1 Help Now