Solved

VBScript error

Posted on 2009-07-01
4
373 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
[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
  • 2
4 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
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 120

Accepted Solution

by:
Rey Obrero (Capricorn1) 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

737 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