Solved

VBScript error

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

828 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