Solved

VBScript error

Posted on 2009-07-01
4
370 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

863 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

25 Experts available now in Live!

Get 1:1 Help Now