Left - Right - Mid Functions

I am having a lot of trouble
understanding the Left - Right and Mid functions and how they work. If i gave you an example of one could you break it down and explain to me what each piece of code is doing?

Lets say that FirstString = < and SecondString = > Lets say TheWholeString = <L>

We will use the Mid Function As the example.

Text1.Text = Mid$(TheWholeString,_ InStr(TheWholeString,_
FirstString) + Len(FirstString),_ InStr(TheWholeString,_
SecondString) - (Len(FirstString) +_
InStr(TheWholeString, FirstString)))

I know after running this code, text1.text would = L
but i cant figure out how it does this. Can you explain
to me what each piece of code in the brackets is doing.
poorboyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

critter017Commented:
Where did you come up with this?  Okay, let's break it down.  You have the Mid function with parameters a, b, c. thus Mid(a, b, c).

a is the string named TheWholeString or <L>

b is InStr(TheWholeString, FirstString) + Len(FirstString)  OR

    InStr(<L>, <) equals 1 since the character first appears in the first position of the target string <L>.  If the target string had been &&<<<L>> then the value of InStr(<L>, <) would be 3.

   Len(<) equals 1 or the length of the target string.

   Therefore b = 1 + 1 = 2

c is InStr(TheWholeString, SecondString) - (Len(FirstString) +                  InStr(TheWholeString, FirstString)))

   InStr(<L>, >) = 3

   Len(<) = 1

   InStr(<L>, <) = 1

So c = 3 - (1 + 1) = 1

Now back to our original formula

Mid(<L>, 2, 1) means start at position number 2 in the string <L> and take 1 charachter.  Thus the answer is L.

More examples:   Mid("Hello", 2, 3) = ell

                            Mid("Good Morning", 3, 6) = od Mor

                            InStr("Hello", l) = 3

                            InStr("Hello", o) = 5

                            Len("Good Morning") = 12

Hope this helps.

 
0
mcriderCommented:
You need to look at the function in  algebraic terms... Always resolve things in parenthesis to get to the lowest absolute, which in this case is the Mid$ function:

Mid$ returns a substring of a string.  There are 3 arguments that are passed to Mid$:

      mid$(String_to_use, Start_of_substring, Length_of_substring)

Here is an algebraic breakdown of the formula. Paste the following into VB so it will make sense.  It will not show up properly here...

Dim FirstString, SecondString, TheWholeString
FirstString = "<"
SecondString = ">"
TheWholeString = "<L>"

text1.Text = Mid$(TheWholeString, InStr(TheWholeString, FirstString) + Len(FirstString), InStr(TheWholeString, SecondString) - (Len(FirstString) + InStr(TheWholeString, FirstString)))
'                                 \                                /   \              /  \                                 /    \              /   \                               /
'                                  \           returns            /     \   returns  /    \            returns            /      \   returns  /     \           returns           /
'                                                 1                  +         1       ,                  3                  -  (       1        +                 1                 )
'
'  Plug the numbers into the mid$ function, so it looks like this:
'
'       text1.Text = Mid$(TheWholeString, 1 + 1, 3 - (1 + 1))
'
'
'  Resolve the numbers again so it looks like this:
'
'       text1.Text = Mid$(TheWholeString, 2, 3 - 2)
'
'
'  Resolve the numbers again so it looks like this:
'
'       text1.Text = Mid$(TheWholeString, 2, 1)




Hope this helps!


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
poorboyAuthor Commented:
I just made the formula up in case
you were wondering. Thanks for the help.
0
mcriderCommented:
You made the formula up?? Ok...

Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.