ricarditopicaron
asked on
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)
Public Sub WriteAFile()
Dim o As Scripting.FileSystemObject
On Error GoTo EnError
Set o = New Scripting.FileSystemObject
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)
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.
Try to disable virus protection just to rule out this possibility. If it makes no difference turn it back on quickly.
In Norton Antivirus is called "Script Blocking".
After I discoverd this I used VB's own file handling.
After I discoverd this I used VB's own file handling.
Here are some functions you can place into a class:
MyData = ReadFile("C:\MyFolder\MyFi le.txt")
Ok = WriteFileOK("C:\MyFolder\M yFile.txt" , MyData)
OK = KillFileOK("C:\MyFolder\My File.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
MyData = ReadFile("C:\MyFolder\MyFi
Ok = WriteFileOK("C:\MyFolder\M
OK = KillFileOK("C:\MyFolder\My
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
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.
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.
Nearly forgot, file copy in VB is easy:
FileCopy FromFileName, ToFileName
FileCopy FromFileName, ToFileName
ASKER
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!
ASKER
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)?
filename$
dir$
folder$
What are this?
It made me remember about my old SVI728 MSX, are they strings? compatibility with old stuff (QBasic)?
ASKER
And something to look for API help it would help like how I use CopyFileA in Kernell32, how I look for that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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
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 **
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 **
It seems ricarditopicaron doen't want to comment on this.
I will change the grade to 'A'.
** Mindphaser - Community Support Moderator **
I will change the grade to 'A'.
** Mindphaser - Community Support Moderator **
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!
Do you anderstand my opnion!
There are some error in my language!
CHeers