Simple question about the "Instr" functions

w11184

Registered User.
Local time
Today, 20:28
Joined
Feb 20, 2012
Messages
41
Hi everyone,

Sorry if this is a bit of a simple question but I just want to understand exactly how the "Instr" function works.

So in my scenario I want to extra the first letter of someone's surname and I actually manage to get it to work using the code below.

Code:
initial2: Mid([FullName],InStr([FullName]," ")+1,1)

However, what I want to know is why it produces an error if "+1" is omitted?

Thanks again. (Apologies, I know this is a basic one)
 
give me a second, editing my post
 
What is the Error it produces? Invalid procedure Call? InStr returns the position of the String you are looking for in your case the Space character.
Code:
? Mid("HelloWorld", InStr("HelloWorld"," "), 1)
If the Function cannot find the String, it would return a value 0.

So the Mid function will have a value.
Code:
? Mid("HelloWorld",0,1)
So the Value ZERO is invalid for (most of the) String functions. Adding 1 makes it a valid argument, as 0+1 would make it 1.

Hope that helps !
 
Thank you very much everyone it has just gotten a lot clearer. The "error" that I get is: #Func!

So I guess that by not putting in +1, it is asking it to return the space which isn't a string.
 

Users who are viewing this thread

Back
Top Bottom