TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Satheesh Palani
NA
333
85.3k
Invalid Procedure Call or Argument in VBA
May 9 2016 10:13 AM
Hi All,
In VBA i am using Following Code to read and write from one text file to another text file with some process.it will work fine for few lines.after that it shows the Error Invalid Procedure call or Argument at the line
tss.WriteLine TextToWrite.
i debug the code the line show the value like flowing screen shot.
I am using following code for read and write
Sub TextFile_ReadData()
Dim fso As New FileSystemObject
Dim ThisLine As String
Dim InsertIndex As Long
Dim TempIndex As Long
Dim CurrentLine As Long
' TextStream Varaiable For Write Data
Dim ts, tss As TextStream
' fso for open a Exsisting file and Read Data
Set ts = fso.OpenTextFile(filereadpath, ForReading, TristateTrue)
' fso for Create a file and Wite Data
Set tss = fso.CreateTextFile(filewritepath, True)
Dim TextToWrite As String
Dim InsertCounter As Long
Dim ArrSplit() As String
Dim SplitString As String
SplitString = "]) VALUES"
TextToWrite = "$"
Do Until ts.AtEndOfStream
'Read the current line
ThisLine = ts.ReadLine '=> Read Line by Line
CurrentLine = CurrentLine + 1
' Read the Line Until the First Spcae and Return the word Count & Assign to TAssign
InsertIndex = InStr(1, ThisLine, "INSERT [dbo].")
'Write the previous line into target file
If (InsertIndex = 1) Then
If (TextToWrite <> "$") Then
tss.WriteLine TextToWrite
End If
Else
If (TextToWrite <> "$") Then
If (InsertCounter = 0) Then
tss.WriteLine TextToWrite
Else
TempIndex = InStrRev(TextToWrite, ",")
tss.WriteLine Left(TextToWrite, TempIndex - 1) & ";"
End If
End If
End If
If (InsertIndex = 1) Then
'Insert Found
InsertCounter = InsertCounter + 1
ArrSplit = Split(ThisLine, SplitString)
If Not IsEmpty(ArrSplit) And UBound(ArrSplit) >= 1 Then
If (InsertCounter = 1) Then
'tss.WriteLine ThisLine & ","
TextToWrite = ThisLine & ","
Else
' tss.WriteLine ArrSplit(1) & ","
TextToWrite = ArrSplit(1) & ","
End If
Else
'tss.WriteLine ThisLine
TextToWrite = ThisLine
InsertCounter = 0
End If
Else
'tss.WriteLine ThisLine
TextToWrite = ThisLine
InsertCounter = 0
End If
Loop
tss.WriteLine TextToWrite
ts.Close
End Sub
can any one try to help me.
Thank you...
Reply
Answers (
2
)
Network Adapter
What out latitude & longitude of a system in Win form c#