Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBS Error

Posted on 2013-11-04
6
Medium Priority
?
403 Views
Last Modified: 2013-11-04
Hello Experts,

I have the following VBScript procedure:

Sub OUTPUTOrders()

'    'Dim fsoOUT As FileSystemObject '*** comment OUT for VBS
'    'Dim fsoFile 'As File '*** comment OUT for VBS
'    'Dim textStream As Scripting.textStream

	Dim fsoOUT, fsoFile
    
    Set fsoOUT = CreateObject("Scripting.FileSystemObject")
    
    If fsoOUT.FileExists(strToImport) Then
    
        Set textStream = fsoOUT.OpenTextFile(strToImport, ForReading)
        
        If textStream.AtEndOfStream = False Then
            strContent = textStream.ReadAll & strContent
        End If
        
        textStream.Close
        Call fsoOUT.DeleteFile(strToImport, True)
        
    End If

    Set fsoFile = fsoOUT.CreateTextFile(strToImport, True)
    fsoFile.Write (strContent)
    fsoFile.Close
    
    Set textStream = Nothing
    Set fsoOUT = Nothing
    Set fsoFile = Nothing
    
End Sub

Open in new window


... but I get Invalid call for

    Set fsoFile = fsoOUT.CreateTextFile(strToImport, True)

Open in new window


Any ideas?

Thanks.
0
Comment
Question by:APD_Toronto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39622992
where do you set the value for strToImport, is it being set with a valid string value representing a file location ?
0
 

Author Comment

by:APD_Toronto
ID: 39623007
This Is the entire script

'Option Explicit
'Dim strContent As String
'Dim strTS As String
'Dim strToImport As String

'Private Sub Form_Load() '***uncomment for debugging***
    Call MainSub
'End Sub  '***uncomment for debugging***

Sub MainSub()

    'Dim strToScan As String
    
    'Client's settings, INLUDING trailing backslash:
        strToScan = "D:\Client FTP Folders\"
        strToImport = "L:\MAS450\TOIMPORT\ALLORDERS.TXT"
        
    'Aleks' settings, INCLUDING trailing backslash ***COMMENT OUT FOLLOWING 2 LINES***:
        strToScan = "S:\Client FTP Folders\"
        strToImport = "S:\ToImport\ALLORDERS.TXT"
    
    strTS = Now
    strContent = ""
            
'    'Dim fso As FileSystemObject '*** comment OUT for VBS
'    'Dim fsoFolder As Folder '*** comment OUT for VBS
'    'Dim fsoSubFolder As Folder '*** comment OUT for VBS
        
    'Dim currFolder As String
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    
    currFolder = strToScan
    
    Call ScanDIR(currFolder)
    
    Set fsoFolder = fso.GetFolder(strToScan)
    
    For Each fsoSubFolder In fsoFolder.SubFolders
    
        currFolder = fsoSubFolder.Path & "\"
        Call ScanDIR(currFolder)
    
    Next
    
    Set fso = Nothing
    Set fsoFolder = Nothing
    Set fsoSubFolder = Nothing
    
    Call OUTPUTOrders

End Sub

Sub ScanDIR(strFolder)

'    'Dim fsoIN As FileSystemObject '*** comment OUT for VBS
'    'Dim fsoINFolder As Folder  '*** comment OUT for VBS
'    'Dim fsoFile As File '*** comment OUT for VBS
'    'Dim textStream As Scripting.textStream
    
    'Dim strFileName As String
    'Dim intLen As Integer
        
    Set fsoIN = CreateObject("Scripting.FileSystemObject")
    Set fsoINFolder = fsoIN.GetFolder(strFolder)
    
    For Each fsoFile In fsoINFolder.Files
    
    
        If (Right(fsoFile.Name, 4) = ".ORD") And (fsoFile.DateCreated < strTS) Then
            
            intLen = Len(fsoFile.Name)
            strFileName = Left(fsoFile.Name, intLen - 4)
            fsoFile.Name = strFileName & ".DONE"
            
            Set textStream = fsoFile.OpenAsTextStream
            strContent = strContent & textStream.ReadAll
            
        End If
    
    Next
    
    Set fsoIN = Nothing
    Set fsoINFolder = Nothing
    Set fsoFile = Nothing
    Set textStream = Nothing

End Sub

Sub OUTPUTOrders()

'    'Dim fsoOUT As FileSystemObject '*** comment OUT for VBS
'    'Dim fsoFile 'As File '*** comment OUT for VBS
'    'Dim textStream As Scripting.textStream

	Dim fsoOUT, fsoFile
    
    Set fsoOUT = CreateObject("Scripting.FileSystemObject")
    
    If fsoOUT.FileExists(strToImport) Then
    
        Set textStream = fsoOUT.OpenTextFile(strToImport, ForReading)
        
        If textStream.AtEndOfStream = False Then
            strContent = textStream.ReadAll & strContent
        End If
        
        textStream.Close
        Call fsoOUT.DeleteFile(strToImport, True)
        
    End If

    Set fsoFile = fsoOUT.CreateTextFile(strToImport, True)
    fsoFile.Write (strContent)
    fsoFile.Close
    
    Set textStream = Nothing
    Set fsoOUT = Nothing
    Set fsoFile = Nothing
    
End Sub

Open in new window

0
 

Author Comment

by:APD_Toronto
ID: 39623009
strToImport is on Li.20
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39623017
Because the strToImport is defined in main sub it is out of scope for the OututOrders sub, either move the definition of the strToImport variable outside of the mainSub sub at the top of the script or within the OutputOrder sub. This also probably applies to other variables you have defined in the main sub used in the other subs.
0
 

Author Comment

by:APD_Toronto
ID: 39623137
I commented out lines 7, 10, 52, but now I get error on 102
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 total points
ID: 39623144
You need to define the constants as below :

Const ForReading = 1, ForWriting = 2, ForAppending = 3
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

636 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