Link to home
Start Free TrialLog in
Avatar of dev_ven
dev_ven

asked on

VBScript error

Why is the following code giving an invalid procedure call or argument error
result = Mid(ThisString, 0, 1)

Open in new window

Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

you start with 1 not 0

result = Mid(ThisString, 1, 1)
dev_ven said:
>>Why is the following code giving an invalid procedure call or argument error

Because you are telling the function to grab 1 character starting at position zero.  That second argument
has to be a positive integer.
Avatar of dev_ven
dev_ven

ASKER

I figured that, but when I change it to 1  I get the following error:  Object Required
for the following code:

oaccess.Run PipeToTab("C:\Documents and Settings\lmb04\My Documents\Personal\Test.txt", "C:\Documents and Settings\lmb04\My Documents\Personal\ConvertedTest.txt")  

why do I get that error?

Below is my full code for my base problem.

Function PipeToTab(InputFile As String, OutputFile As String)
Dim ThisString As String
Dim NewString As String
Dim A As Integer
Dim result As String
Open InputFile For Input As #1
Open OutputFile For Output As #2

NewString = ""
Do While Not EOF(1)

Line Input #1, ThisString
For A = 1 To Len(ThisString)
If Mid(ThisString, A, 1) = "|" Then
NewString = NewString & Chr$(9)
Else
NewString = NewString & Mid(ThisString, A, 1)
End If
Next

Print #2, NewString
Loop
End Function
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial