Solved

VBScript error

Posted on 2009-07-01
4
369 Views
Last Modified: 2012-05-07
Why is the following code giving an invalid procedure call or argument error
result = Mid(ThisString, 0, 1)

Open in new window

0
Comment
Question by:dev_ven
  • 2
4 Comments
 
LVL 119

Expert Comment

by:Rey Obrero
ID: 24757455
you start with 1 not 0

result = Mid(ThisString, 1, 1)
0
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24757465
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.
0
 

Author Comment

by:dev_ven
ID: 24757572
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
0
 
LVL 119

Accepted Solution

by:
Rey Obrero earned 500 total points
ID: 24757816
if you are running the codes in an Access application

change this

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


to

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


and use this codes

Sub 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
close #1
close #2
End sub



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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

706 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

18 Experts available now in Live!

Get 1:1 Help Now