View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default VBA mid() function

Hi Rick,

If you run the loop first with Mid$(S, L, L) then with Mid$(S, L, 1) I think
your question is answered. That is, "assuming" the OP wants each character
of the sample string returned individually.

Regards,
Peter T


"Rick Rothstein" wrote in message
...
I'm not "picking" on your Charlie, it's just I needed to attach this note
to either you message or Peter T's message... I chose yours.

Both you and Peter made the same suggestion (to change the second L to a
one)... my question to the both of you is...

How does that explain the OP's statement "The above
code returns the correct value only on the 1st iteration"?

It would seem that changing the second L to a one would make it so the
first iteration would fail, not succeed.

--
Rick (MVP - Excel)


"Charlie" wrote in message
...
Debug.Print Mid$(S, L, 1)

Use a 1 not "L"

"vello" wrote:

Using XP & Excel2002 to find a string in another string, gets me weird
results:
Dim S As String
Dim L As Long

S = "0123456789"
For L = 1 To 10
Debug.Print Mid$(S, L, L)
Next

The above code returns the correct value only on the 1st iteration.
Thereafter the Mid$ keeps growing.

Is there an API procedure to accomplish this? Can't seem to find it.