Invalid procedure call or argument (Error 5)

  • Thread starter Thread starter John Bruen
  • Start date Start date
J

John Bruen

Why do I get the above error message when I try and set
certain positions of a string using the following
statement?

Dim StringX as string
Dim MyStart as Integer
Dim MyLength as Integer
StringX = ""
MyStart = 5
MyLength = 10
MyString = "aaaaaaaaaa"

Mid$(StringX, MyStart, MyLength) = Mystring

Is there any other way to do this?
 
John Bruen said:
Why do I get the above error message when I try and set
certain positions of a string using the following
statement?

Dim StringX as string
Dim MyStart as Integer
Dim MyLength as Integer
StringX = ""
MyStart = 5
MyLength = 10
MyString = "aaaaaaaaaa"

Mid$(StringX, MyStart, MyLength) = Mystring

Is there any other way to do this?

The starting point, MyStart, you've specified is greater than the length
of the string. What is it you're trying to do?
 
Thanks for the fast reply Dirk.

I'm trying to build a line from a mainframe CICS Map with
the line and position to show how the screen looks.

DO I have to initialize the string to spaces first or a
length. .

John
 
What are you trying to do with the last statement:

Mid$(StringX, MyStart, MyLength) = Mystring ???

Note that this is an *assignment* statement where you assign the *variable*
on the left of the equal sign with the value on the right of the equal sign.
In your statement, the LHS is an in-built function which *returns* a value.
You cannot assign a value to an inbuilt function!

Don't confuse a mathematical equation (commutative) with a VBA assignment
statement (not commutative) just because of the equal sign.

You haven't dimensioned the variable MyString either. Make sure you have
the Option Explicit in your module.

Sorry, I can't suggest a solution because I am not sure what you are trying
to do from the statement.
 
Van T. Dinh said:
What are you trying to do with the last statement:

Mid$(StringX, MyStart, MyLength) = Mystring ???

Note that this is an *assignment* statement where you assign the
*variable* on the left of the equal sign with the value on the right
of the equal sign. In your statement, the LHS is an in-built function
which *returns* a value. You cannot assign a value to an inbuilt
function!

Van -

Actually, there is a Mid (and Mid$) *statement* that operates to assign
a string to the specified positions in another string. Mr. Bruen's
statement would be valid if StringX were at least 5 characters long.
 
Dirk

Once I Initialized the StringX variable to spaces,
everything worked fine.

Thanks again for the help.
John
 
John Bruen said:
Thanks for the fast reply Dirk.

I'm trying to build a line from a mainframe CICS Map with
the line and position to show how the screen looks.

DO I have to initialize the string to spaces first or a
length. .

John

Probably your best bet, based on what I think you're trying to do, is to
first initialize StringX to as many spaces as the final output is
supposed to contain. So if StringX represents a screen line of, say, 80
characters, then just change this line:
StringX = ""

to this:

StringX = Space(80)

Then you can go ahead and use the Mid statement to overlay specific
areas of the line.
 
I better read up on this. I have never seen it used this way.

Sorry, John.

Thanks, Dirk.
 
Back
Top