Code Question

N

NEWER USER

When typing code in an Event Procedure, I have a long line of text where I
can't see all the code on my screen. I see examples where others type an
underscore "_" and word wrap to the next line. When I enter this character
and go to next line, I get an unexpected error message and all turns red.
What am I doing wrong?

Thanks for any help
 
J

Jack Leach

That's actually a space, followed by the underscore... " _"

So, if you have this:

x = Right( _
"SomeString", _
4 _
)

it should work, but this wouldn't...

x = Right(_
"SomeString",_
4_
)

Also, note that this cannot be used inside a string (quotes). For example...

x = Right("Some _
String", 4)

is incorrect... you need to contencate (&) the two peices of string together
to...

x = Right("Some" _
& "String", 4)

or

x = Right("Some" & _
"String", 4)


that should be about all you need to know...


hth

--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
I suppose if you really wanted to prove to yourself...


x = Right( _
"S" & _
"o" & _
"m" & _
"e" & _
"S" & _
"t" & _
"r" & _
"i" & _
"n" & _
"g", _
4, _
)


How cool would it be if everyone wrote code like that?!?! <g>
<snip>

I realise you're not being serious, but its worth bearing in mind that VBA
imposes a 20-line limit on continuations. I discovered this when I coded my
SQL formatting add-in.
 
N

NEWER USER

Thank you so much for getting me pointed in the right direction. Happy
Holidays!
 
J

Jack Leach

Thanks Stuart, definately worth nothing. I can see how SQL formatting might
lead to this....


One last note to OP, you can't use this line continuation in the middle of a
function name or after a bang (!) or dot operator... the following would not
compile:

x = Rig _
ht("SomeString", 4)

x = Forms!frmHome!ctlThis _
Control.Value

x = Forms!frmHome!ctlThisControl. _
Value

but you could use:

x = Forms!frmHome.Controls( _
"ctlThisControl").Value


--
Jack Leach
www.tristatemachine.com

"I haven''t failed, I''ve found ten thousand ways that don''t work."
-Thomas Edison (1847-1931)
 
S

Stuart McCall

Jack Leach said:
Thanks Stuart, definately worth nothing

Well if that's how it is I'm going to play with someone else. And I'm taking
my bat & ball with me...

;-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top